diff --git a/src/client/inc/tscLog.h b/src/client/inc/tscLog.h index 5273a87ea0d0549420acf2b6679f50ce22159ebc..ab7806f9df8a5122f0d3f2276b0c4b5dc0251e45 100644 --- a/src/client/inc/tscLog.h +++ b/src/client/inc/tscLog.h @@ -28,9 +28,9 @@ extern int8_t tscEmbedded; #define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0) #define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0) #define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0) -#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0) -#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0) -#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0) +#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosDbgPrintLog("TSC ", tscEmbedded ? 255 : cDebugFlag, __FILE__, __LINE__,__VA_ARGS__); }} while(0) +#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosDbgPrintLog("TSC ", cDebugFlag, __FILE__, __LINE__, __VA_ARGS__); }} while(0) +#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosDbgPrintLog("TSC ", cDebugFlag, __FILE__, __LINE__,__VA_ARGS__); }} while(0) #define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", cDebugFlag, __VA_ARGS__); }} while(0) #ifdef __cplusplus diff --git a/src/util/inc/tlog.h b/src/util/inc/tlog.h index 1f6a81d4b49a8a44f5c60da9a6c901be96e5d8f6..52f78c4a624faf65b2533866d8d11236eb70a23e 100644 --- a/src/util/inc/tlog.h +++ b/src/util/inc/tlog.h @@ -41,6 +41,13 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) #endif ; +void taosDbgPrintLog(const char *flags, int32_t dflag, char *file, int line, const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 5, 6))) +#endif +; + + void taosPrintLongString(const char * flags, int32_t dflag, const char *format, ...) #ifdef __GNUC__ __attribute__((format(printf, 3, 4))) diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index e0fe51e22a6405273cbb60fbfa04d3a5956105b0..5b14db8090e6bacf61e9f4c77697c154ab0aced3 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -345,6 +345,66 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { return 0; } +void taosDbgPrintLog(const char *flags, int32_t dflag, char *file, int line, const char *format, ...) { + if (tsTotalLogDirGB != 0 && tsAvailLogDirGB < tsMinimalLogDirGB) { + printf("server disk:%s space remain %.3f GB, total %.1f GB, stop print log.\n", tsLogDir, tsAvailLogDirGB, tsTotalLogDirGB); + fflush(stdout); + return; + } + + va_list argpointer; + char buffer[MAX_LOGLINE_BUFFER_SIZE] = { 0 }; + int32_t len; + struct tm Tm, *ptm; + struct timeval timeSecs; + time_t curTime; + + gettimeofday(&timeSecs, NULL); + curTime = timeSecs.tv_sec; + ptm = localtime_r(&curTime, &Tm); + + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%08" PRIx64 " %8.8s:%4d ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, + ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(), file, line); + len += sprintf(buffer + len, "%s", flags); + + va_start(argpointer, format); + int32_t writeLen = vsnprintf(buffer + len, MAX_LOGLINE_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; + } else { + len += writeLen; + } + va_end(argpointer); + + if (len > MAX_LOGLINE_SIZE) len = MAX_LOGLINE_SIZE; + + buffer[len++] = '\n'; + buffer[len] = 0; + + if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->fd >= 0) { + if (tsAsyncLog) { + taosPushLogBuffer(tsLogObj.logHandle, buffer, len); + } else { + taosWrite(tsLogObj.logHandle->fd, buffer, len); + } + + if (tsLogObj.maxLines > 0) { + atomic_add_fetch_32(&tsLogObj.lines, 1); + + if ((tsLogObj.lines > tsLogObj.maxLines) && (tsLogObj.openInProgress == 0)) taosOpenNewLogFile(); + } + } + + if (dflag & DEBUG_SCREEN) taosWrite(1, buffer, (uint32_t)len); + if (dflag == 255) nInfo(buffer, len); +} + + void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { if (tsTotalLogDirGB != 0 && tsAvailLogDirGB < tsMinimalLogDirGB) { printf("server disk:%s space remain %.3f GB, total %.1f GB, stop print log.\n", tsLogDir, tsAvailLogDirGB, tsTotalLogDirGB);