diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index 972361fd6855ae789a313746bcca1f18ce2fb533..a5372014d5b7997049813c8eb8240c4c440b4ead 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -126,10 +126,17 @@ typedef struct { SMonDiskDesc tempdir; } SMonDiskInfo; +typedef enum { + MON_LEVEL_ERROR = 0, + MON_LEVEL_INFO = 1, + MON_LEVEL_DEBUG = 2, + MON_LEVEL_TRACE = 3, +} EMonLogLevel; + typedef struct { - int64_t ts; - int8_t level; - char content[MON_LOG_LEN]; + int64_t ts; + EMonLogLevel level; + char content[MON_LOG_LEN]; } SMonLogItem; typedef struct SMonInfo SMonInfo; diff --git a/source/libs/monitor/src/monitor.c b/source/libs/monitor/src/monitor.c index 14375a4ef6ae73cba2aa3f1e4901cc416f48a3e5..949fe3e5e7591938288e278048a1146b928d32ac 100644 --- a/source/libs/monitor/src/monitor.c +++ b/source/libs/monitor/src/monitor.c @@ -270,6 +270,21 @@ void monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) { tjsonAddDoubleToObject(pTempdirJson, "total", pInfo->tempdir.size.total); } +static const char *monLogLevelStr(EMonLogLevel level) { + switch (level) { + case MON_LEVEL_ERROR: + return "error"; + case MON_LEVEL_INFO: + return "info"; + case MON_LEVEL_DEBUG: + return "debug"; + case MON_LEVEL_TRACE: + return "trace"; + default: + return "undefine"; + } +} + static void monSetLogInfo(SMonInfo *pMonitor) { SJson *pJson = tjsonCreateObject(); if (pJson == NULL) return; @@ -291,7 +306,7 @@ static void monSetLogInfo(SMonInfo *pMonitor) { taosFormatUtcTime(buf, sizeof(buf), pLogItem->ts, TSDB_TIME_PRECISION_MILLI); tjsonAddStringToObject(pLogJson, "ts", buf); - tjsonAddDoubleToObject(pLogJson, "level", pLogItem->level); + tjsonAddStringToObject(pLogJson, "level", monLogLevelStr(pLogItem->level)); tjsonAddStringToObject(pLogJson, "content", pLogItem->content); if (tjsonAddItemToArray(pLogsJson, pLogJson) != 0) tjsonDelete(pLogJson); diff --git a/source/libs/monitor/test/monTest.cpp b/source/libs/monitor/test/monTest.cpp index ad48ed5407796f34f1ea4d14084c013a2e29e52d..49abd4803ac314acf68cabf5a06efff22e3c6d80 100644 --- a/source/libs/monitor/test/monTest.cpp +++ b/source/libs/monitor/test/monTest.cpp @@ -195,19 +195,19 @@ void MonitorTest::GetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) { void MonitorTest::AddLogInfo1() { SMonLogItem log1 = {0}; log1.ts = taosGetTimestampMs(); - log1.level = 1; + log1.level = MON_LEVEL_INFO; strcpy(log1.content, "1 -------------------------- a"); monAddLogItem(&log1); SMonLogItem log2 = {0}; log2.ts = taosGetTimestampMs(); - log2.level = 1; + log2.level = MON_LEVEL_ERROR; strcpy(log2.content, "1 ------------------------ b"); monAddLogItem(&log2); SMonLogItem log3 = {0}; log3.ts = taosGetTimestampMs(); - log3.level = 1; + log3.level = MON_LEVEL_DEBUG; strcpy(log3.content, "1 ------- c"); monAddLogItem(&log3); } @@ -215,13 +215,13 @@ void MonitorTest::AddLogInfo1() { void MonitorTest::AddLogInfo2() { SMonLogItem log1; log1.ts = taosGetTimestampMs(); - log1.level = 01; + log1.level = MON_LEVEL_ERROR; strcpy(log1.content, "2 ------- a"); monAddLogItem(&log1); SMonLogItem log2; log2.ts = taosGetTimestampMs(); - log2.level = 0; + log2.level = MON_LEVEL_ERROR; strcpy(log2.content, "2 ------- b"); monAddLogItem(&log2); }