提交 09f27bdc 编写于 作者: S Shengliang Guan

record log for monitoring

上级 17b71c1d
...@@ -25,13 +25,11 @@ static SMonitor tsMonitor = {0}; ...@@ -25,13 +25,11 @@ static SMonitor tsMonitor = {0};
void monRecordLog(int64_t ts, ELogLevel level, const char *content) { void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
pthread_mutex_lock(&tsMonitor.lock); pthread_mutex_lock(&tsMonitor.lock);
int32_t size = taosArrayGetSize(tsMonitor.logs); int32_t size = taosArrayGetSize(tsMonitor.logs);
if (size >= tsMonitor.maxLogs) { if (size < tsMonitor.maxLogs) {
uInfo("too many logs for monitor");
} else {
SMonLogItem item = {.ts = ts, .level = level}; SMonLogItem item = {.ts = ts, .level = level};
SMonLogItem *pItem = taosArrayPush(tsMonitor.logs, &item); SMonLogItem *pItem = taosArrayPush(tsMonitor.logs, &item);
if (pItem != NULL) { if (pItem != NULL) {
tstrncpy(pItem->content, content, sizeof(item.content)); tstrncpy(pItem->content, content, MON_LOG_LEN);
} }
} }
pthread_mutex_unlock(&tsMonitor.lock); pthread_mutex_unlock(&tsMonitor.lock);
...@@ -53,6 +51,7 @@ int32_t monInit(const SMonCfg *pCfg) { ...@@ -53,6 +51,7 @@ int32_t monInit(const SMonCfg *pCfg) {
} }
void monCleanup() { void monCleanup() {
tsLogFp = NULL;
taosArrayDestroy(tsMonitor.logs); taosArrayDestroy(tsMonitor.logs);
tsMonitor.logs = NULL; tsMonitor.logs = NULL;
pthread_mutex_destroy(&tsMonitor.lock); pthread_mutex_destroy(&tsMonitor.lock);
......
...@@ -431,24 +431,31 @@ static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *b ...@@ -431,24 +431,31 @@ static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *b
void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) { void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) {
if (!osLogSpaceAvailable()) return; if (!osLogSpaceAvailable()) return;
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
char buffer[LOG_MAX_LINE_BUFFER_SIZE]; char buffer[LOG_MAX_LINE_BUFFER_SIZE];
int32_t len = taosBuildLogHead(buffer, flags); int32_t len = taosBuildLogHead(buffer, flags);
va_list argpointer; va_list argpointer;
va_start(argpointer, format); va_start(argpointer, format);
len += vsnprintf(buffer + len, LOG_MAX_LINE_BUFFER_SIZE - len, format, argpointer); int32_t writeLen = len + vsnprintf(buffer + len, LOG_MAX_LINE_BUFFER_SIZE - len, format, argpointer);
va_end(argpointer); va_end(argpointer);
if (len > LOG_MAX_LINE_SIZE) len = LOG_MAX_LINE_SIZE; if (writeLen > LOG_MAX_LINE_SIZE) writeLen = LOG_MAX_LINE_SIZE;
buffer[len++] = '\n'; buffer[writeLen++] = '\n';
buffer[len] = 0; buffer[writeLen] = 0;
taosPrintLogImp(level, dflag, buffer, len); taosPrintLogImp(level, dflag, buffer, writeLen);
if (tsLogFp && level <= DEBUG_INFO) {
buffer[writeLen - 1] = 0;
(*tsLogFp)(taosGetTimestampMs(), level, buffer + len);
}
} }
void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) { void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) {
if (!osLogSpaceAvailable()) return; if (!osLogSpaceAvailable()) return;
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
char buffer[LOG_MAX_LINE_DUMP_BUFFER_SIZE]; char buffer[LOG_MAX_LINE_DUMP_BUFFER_SIZE];
int32_t len = taosBuildLogHead(buffer, flags); int32_t len = taosBuildLogHead(buffer, flags);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册