From 80d0ea135c86c65e52e831d5ba5302da7c87569f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 27 Feb 2022 10:32:15 +0800 Subject: [PATCH] refact log --- include/util/compare.h | 14 ++++++-------- include/util/tlog.h | 3 +-- source/util/src/tlog.c | 36 ++++++++++++++++++------------------ 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/include/util/compare.h b/include/util/compare.h index 6305334e02..ece8ffaf42 100644 --- a/include/util/compare.h +++ b/include/util/compare.h @@ -16,17 +16,18 @@ #ifndef _TD_UTIL_COMPARE_H_ #define _TD_UTIL_COMPARE_H_ +#include "os.h" + #ifdef __cplusplus extern "C" { #endif -#include "os.h" -#define TSDB_PATTERN_MATCH 0 -#define TSDB_PATTERN_NOMATCH 1 -#define TSDB_PATTERN_NOWILDCARDMATCH 2 +#define TSDB_PATTERN_MATCH 0 +#define TSDB_PATTERN_NOMATCH 1 +#define TSDB_PATTERN_NOWILDCARDMATCH 2 #define TSDB_PATTERN_STRING_DEFAULT_LEN 100 -#define TSDB_REGEX_STRING_DEFAULT_LEN 128 +#define TSDB_REGEX_STRING_DEFAULT_LEN 128 #define FLT_COMPAR_TOL_FACTOR 4 #define FLT_EQUAL(_x, _y) (fabs((_x) - (_y)) <= (FLT_COMPAR_TOL_FACTOR * FLT_EPSILON)) @@ -62,7 +63,6 @@ int32_t setChkNotInBytes8(const void *pLeft, const void *pRight); int32_t compareChkInString(const void *pLeft, const void *pRight); int32_t compareChkNotInString(const void *pLeft, const void *pRight); - int32_t compareInt8Val(const void *pLeft, const void *pRight); int32_t compareInt16Val(const void *pLeft, const void *pRight); int32_t compareInt32Val(const void *pLeft, const void *pRight); @@ -83,7 +83,6 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight); int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight); int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight); - int32_t compareInt8ValDesc(const void *pLeft, const void *pRight); int32_t compareInt16ValDesc(const void *pLeft, const void *pRight); int32_t compareInt32ValDesc(const void *pLeft, const void *pRight); @@ -102,7 +101,6 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight); __compar_fn_t getComparFunc(int32_t type, int32_t optr); - #ifdef __cplusplus } #endif diff --git a/include/util/tlog.h b/include/util/tlog.h index 166e186508..68cb5bddd9 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -22,7 +22,6 @@ extern "C" { #endif -extern bool tsLogInited; extern bool tsAsyncLog; extern int32_t tsNumOfLogLines; extern int32_t tsLogKeepDays; @@ -55,7 +54,7 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles); void taosCloseLog(); void taosResetLog(); void taosSetAllDebugFlag(int32_t flag); -void taosDumpData(unsigned char *msg, int32_t len); +void taosDumpData(uint8_t *msg, int32_t len); void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) #ifdef __GNUC__ diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 567885b0f4..b64c6f75a4 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -19,12 +19,12 @@ #include "tutil.h" #include "ulog.h" -#define MAX_LOGLINE_SIZE (1000) -#define MAX_LOGLINE_BUFFER_SIZE (MAX_LOGLINE_SIZE + 10) -#define MAX_LOGLINE_CONTENT_SIZE (MAX_LOGLINE_SIZE - 100) -#define MAX_LOGLINE_DUMP_SIZE (65 * 1024) -#define MAX_LOGLINE_DUMP_BUFFER_SIZE (MAX_LOGLINE_DUMP_SIZE + 10) -#define MAX_LOGLINE_DUMP_CONTENT_SIZE (MAX_LOGLINE_DUMP_SIZE - 100) +#define LOG_MAX_LINE_SIZE (1000) +#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 10) +#define LOG_MAX_LINE_CONTENT_SIZE (LOG_MAX_LINE_SIZE - 100) +#define LOG_MAX_LINE_DUMP_SIZE (65 * 1024) +#define LOG_MAX_LINE_DUMP_BUFFER_SIZE (LOG_MAX_LINE_DUMP_SIZE + 10) +#define LOG_MAX_LINE_DUMP_CONTENT_SIZE (LOG_MAX_LINE_DUMP_SIZE - 100) #define LOG_FILE_NAME_LEN 300 #define TSDB_DEFAULT_LOG_BUF_SIZE (20 * 1024 * 1024) // 20MB @@ -383,7 +383,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { if (!osLogSpaceAvailable()) return; va_list argpointer; - char buffer[MAX_LOGLINE_BUFFER_SIZE] = {0}; + char buffer[LOG_MAX_LINE_BUFFER_SIZE] = {0}; int32_t len; struct tm Tm, *ptm; struct timeval timeSecs; @@ -398,20 +398,20 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { len += sprintf(buffer + len, "%s", flags); va_start(argpointer, format); - int32_t writeLen = vsnprintf(buffer + len, MAX_LOGLINE_CONTENT_SIZE, format, argpointer); + int32_t writeLen = vsnprintf(buffer + len, LOG_MAX_LINE_CONTENT_SIZE, format, argpointer); if (writeLen <= 0) { - char tmp[MAX_LOGLINE_DUMP_BUFFER_SIZE] = {0}; - writeLen = vsnprintf(tmp, MAX_LOGLINE_DUMP_CONTENT_SIZE, format, argpointer); - strncpy(buffer + len, tmp, MAX_LOGLINE_CONTENT_SIZE); - len += MAX_LOGLINE_CONTENT_SIZE; - } else if (writeLen >= MAX_LOGLINE_CONTENT_SIZE) { - len += MAX_LOGLINE_CONTENT_SIZE; + char tmp[LOG_MAX_LINE_DUMP_BUFFER_SIZE] = {0}; + writeLen = vsnprintf(tmp, LOG_MAX_LINE_DUMP_CONTENT_SIZE, format, argpointer); + strncpy(buffer + len, tmp, LOG_MAX_LINE_CONTENT_SIZE); + len += LOG_MAX_LINE_CONTENT_SIZE; + } else if (writeLen >= LOG_MAX_LINE_CONTENT_SIZE) { + len += LOG_MAX_LINE_CONTENT_SIZE; } else { len += writeLen; } va_end(argpointer); - if (len > MAX_LOGLINE_SIZE) len = MAX_LOGLINE_SIZE; + if (len > LOG_MAX_LINE_SIZE) len = LOG_MAX_LINE_SIZE; buffer[len++] = '\n'; buffer[len] = 0; @@ -460,7 +460,7 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . if (!osLogSpaceAvailable()) return; va_list argpointer; - char buffer[MAX_LOGLINE_DUMP_BUFFER_SIZE]; + char buffer[LOG_MAX_LINE_DUMP_BUFFER_SIZE]; int32_t len; struct tm Tm, *ptm; struct timeval timeSecs; @@ -475,10 +475,10 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . len += sprintf(buffer + len, "%s", flags); va_start(argpointer, format); - len += vsnprintf(buffer + len, MAX_LOGLINE_DUMP_CONTENT_SIZE, format, argpointer); + len += vsnprintf(buffer + len, LOG_MAX_LINE_DUMP_CONTENT_SIZE, format, argpointer); va_end(argpointer); - if (len > MAX_LOGLINE_DUMP_SIZE) len = MAX_LOGLINE_DUMP_SIZE; + if (len > LOG_MAX_LINE_DUMP_SIZE) len = LOG_MAX_LINE_DUMP_SIZE; buffer[len++] = '\n'; buffer[len] = 0; -- GitLab