1. 增加日志级别打印

This commit is contained in:
coffee 2026-03-28 18:31:51 +08:00
parent e63e2899ac
commit fa9a7df818

View File

@ -289,6 +289,22 @@ uint32_t HDLogGetTime()
return 0;
}
static const char *GetLogLevelName(uint8_t level)
{
switch (level) {
case kLogLevelDebug:
return "D";
case kLogLevelError:
return "E";
case kLogLevelTrace:
return "T";
default:
break;
}
return "U";
}
void HDLogOut(uint8_t ext, uint8_t level, const char *fileName, const char *funcName, int line, const char *format, ...)
{
if (HBitGet(sLogItem, kLogLevelSwitch) == 0)
@ -320,11 +336,11 @@ void HDLogOut(uint8_t ext, uint8_t level, const char *fileName, const char *func
// 日志前缀基础信息, 文件名, 函数名, 行号
#define _LOG_BASE_ARGS _BASENAME(__FILE__), __func__, __LINE__
#define _LOG_BASE_INFO "[%s:%s:%d]"
#define _LOG_BASE_INFO "[%s:%s:%d:%s]"
#define _LOG_BASE_INFO_COLOR "[" _LOG_COLOR_BLUE \
"%s:%s:" _LOG_COLOR_PURPLE \
"%d" _LOG_COLOR_END \
"]"
":%s]"
#define _LOG_USE_COLOR(outColor) if (color) { printf(outColor); }
@ -340,11 +356,11 @@ void HDLogOut(uint8_t ext, uint8_t level, const char *fileName, const char *func
if (color)
{
printf(_LOG_BASE_INFO_COLOR, fileName, funcName, line);
printf(_LOG_BASE_INFO_COLOR, fileName, funcName, line, GetLogLevelName(level));
}
else
{
printf(_LOG_BASE_INFO, fileName, funcName, line);
printf(_LOG_BASE_INFO, fileName, funcName, line, GetLogLevelName(level));
}
if (HBitGet(sLogItem, kLogLevelStack))