record log for monitoring
This commit is contained in:
parent
17b71c1d0c
commit
09f27bdcce
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue