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.
58 lines
1.8 KiB
58 lines
1.8 KiB
4 months ago
|
/*
|
||
|
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2022. All rights reserved.
|
||
|
* Description: Support hwdisplay hal adaptation interface
|
||
|
* Author: Hisilicon
|
||
|
* Created: 2022-12-28
|
||
|
*/
|
||
|
|
||
|
#include "LogTool.h"
|
||
|
#include "securec.h"
|
||
|
#include "td_type.h"
|
||
|
|
||
|
static const td_s32 LOG_BUF_SIZE = 1024;
|
||
|
|
||
|
namespace android {
|
||
|
int LogTool::level = static_cast<int>(LOG_PRIO_E::LOG_BUTT);
|
||
|
|
||
|
td_s32 LogTool::PrintLog(LOG_PRIO_E prio, const char *tag, const char *func, unsigned int line, const char *fmt, ...)
|
||
|
{
|
||
|
if (tag == nullptr) {
|
||
|
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 LOG_PRIO_E::LOG_ERROR:
|
||
|
android_printLog(ANDROID_LOG_ERROR, tag, "\033[31m[%s:%d] %s\033[0m", func, line, buf); // red
|
||
|
break;
|
||
|
case LOG_PRIO_E::LOG_WARN:
|
||
|
android_printLog(ANDROID_LOG_WARN, tag, "\033[35m[%s:%d] %s\033[0m", func, line, buf); // purple
|
||
|
break;
|
||
|
case LOG_PRIO_E::LOG_INFO:
|
||
|
android_printLog(ANDROID_LOG_INFO, tag, "\e[36m[%s:%d] %s\e[0m", func, line, buf); // deep green
|
||
|
break;
|
||
|
case LOG_PRIO_E::LOG_DEBUG:
|
||
|
android_printLog(ANDROID_LOG_DEBUG, tag, "[%s:%d] %s", func, line, buf);
|
||
|
break;
|
||
|
case LOG_PRIO_E::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;
|
||
|
}
|
||
|
}
|