You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.3 KiB
85 lines
2.3 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2012-2019. All rights reserved.
|
|
* Description:
|
|
* Author:
|
|
* Create:
|
|
*/
|
|
|
|
#include "MwLogTool.h"
|
|
#include "SystemSetting.h"
|
|
#include "ITVManager.h"
|
|
#include "securec.h"
|
|
#include "td_type.h"
|
|
|
|
static const td_s32 LOG_BUF_SIZE = 1024;
|
|
|
|
namespace android {
|
|
int MwLogTool::level = ATV_LOG_BUTT;
|
|
|
|
td_s32 MwLogTool::PrintLog(
|
|
ATV_LOG_PRIO_E prio, const char *tag, const char *func, unsigned int line, const char *fmt, ...)
|
|
{
|
|
if (tag == nullptr) {
|
|
return TD_FAILURE;
|
|
}
|
|
|
|
if (TVCreator::getmITVManagerValue() != nullptr) {
|
|
if (prio < getLogLevel()) {
|
|
return TD_FAILURE;
|
|
}
|
|
}
|
|
|
|
td_char buf[LOG_BUF_SIZE] = { 0 };
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
int ret = vsnprintf_s(buf, sizeof(buf), sizeof(buf) - 1, fmt, ap);
|
|
if (ret == -1) {
|
|
TLOGE("vsnprintf_s failed, ret = %d", ret);
|
|
va_end(ap);
|
|
return TD_FAILURE;
|
|
}
|
|
va_end(ap);
|
|
|
|
switch (prio) {
|
|
case ATV_LOG_ERROR:
|
|
android_printLog(ANDROID_LOG_ERROR, tag, "\033[31m[%s:%d] %s\033[0m", func, line, buf); // red
|
|
break;
|
|
case ATV_LOG_WARN:
|
|
android_printLog(ANDROID_LOG_WARN, tag, "\033[35m[%s:%d] %s\033[0m", func, line, buf); // purple
|
|
break;
|
|
case ATV_LOG_INFO:
|
|
android_printLog(ANDROID_LOG_INFO, tag, "\e[36m[%s:%d] %s\e[0m", func, line, buf); // deep green
|
|
break;
|
|
case ATV_LOG_DEBUG:
|
|
android_printLog(ANDROID_LOG_DEBUG, tag, "[%s:%d] %s", func, line, buf);
|
|
break;
|
|
case ATV_LOG_VERBOSE:
|
|
android_printLog(ANDROID_LOG_VERBOSE, tag, "[%s:%d] %s", func, line, buf);
|
|
break;
|
|
default:
|
|
android_printLog(ANDROID_LOG_UNKNOWN, tag, "[%s:%d] %s", func, line, buf);
|
|
break;
|
|
}
|
|
|
|
return TD_SUCCESS;
|
|
}
|
|
|
|
td_s32 MwLogTool::getLogLevel()
|
|
{
|
|
ISystemSetting *pISystemSetting = TVCreator::create()->getSystemSetting();
|
|
if (pISystemSetting == nullptr) {
|
|
ALOGE("[%s %d] getSystemSetting failure\n", __FUNCTION__, __LINE__);
|
|
return TD_FAILURE;
|
|
}
|
|
|
|
if (level == ATV_LOG_BUTT) {
|
|
level = pISystemSetting->getPrintLevel();
|
|
}
|
|
if (level > ATV_LOG_ERROR || level < ATV_LOG_VERBOSE) {
|
|
level = ATV_LOG_VERBOSE;
|
|
}
|
|
|
|
return level;
|
|
}
|
|
}
|