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

record log for monitoring

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