提交 d4a280d8 编写于 作者: S Shengliang Guan

log level

上级 7b054eac
......@@ -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;
......
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册