diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index a5372014d5b7997049813c8eb8240c4c440b4ead..0041f3ac5fdb42ad7ac9337e32be265fa8a541ac 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -18,6 +18,7 @@ #include "tarray.h" #include "tdef.h" +#include "tlog.h" #ifdef __cplusplus extern "C" { @@ -126,19 +127,6 @@ typedef struct { SMonDiskDesc tempdir; } SMonDiskInfo; -typedef enum { - MON_LEVEL_ERROR = 0, - MON_LEVEL_INFO = 1, - MON_LEVEL_DEBUG = 2, - MON_LEVEL_TRACE = 3, -} EMonLogLevel; - -typedef struct { - int64_t ts; - EMonLogLevel level; - char content[MON_LOG_LEN]; -} SMonLogItem; - typedef struct SMonInfo SMonInfo; typedef struct { @@ -149,7 +137,7 @@ typedef struct { int32_t monInit(const SMonCfg *pCfg); void monCleanup(); -void monAddLogItem(SMonLogItem *pItem); +void monRecordLog(int64_t ts, ELogLevel level, const char *content); SMonInfo *monCreateMonitorInfo(); void monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo); diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 6d3f97fc4e3e0d0f335af3cc269713309f739e35..1f56254476abbd1ea5a264a5a591add2bfd33087 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -168,20 +168,18 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STabl extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize); - #define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE #define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE #define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE #define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE -#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0) -#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0) -#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", qDebugFlag, __VA_ARGS__); }} while(0) -#define qInfo(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0) -#define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0) -#define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0) -#define qDebugL(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY ", qDebugFlag, __VA_ARGS__); }} while(0) - +#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", DEBUG_FATAL, qDebugFlag, __VA_ARGS__); }} while(0) +#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", DEBUG_ERROR, qDebugFlag, __VA_ARGS__); }} while(0) +#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", DEBUG_WARN, qDebugFlag, __VA_ARGS__); }} while(0) +#define qInfo(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", DEBUG_INFO, qDebugFlag, __VA_ARGS__); }} while(0) +#define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); }} while(0) +#define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); }} while(0) +#define qDebugL(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); }} while(0) #ifdef __cplusplus } diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index f90dbb97fe1b2860cd103e878ba25787be7102ab..32fcd95948d7ef1e481f04d484c9e54070c47f4e 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -24,43 +24,41 @@ extern "C" { #endif -extern int32_t wDebugFlag; - -#define wFatal(...) \ - { \ - if (wDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("WAL FATAL ", 255, __VA_ARGS__); \ - } \ +#define wFatal(...) \ + { \ + if (wDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("WAL FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ + } \ } -#define wError(...) \ - { \ - if (wDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("WAL ERROR ", 255, __VA_ARGS__); \ - } \ +#define wError(...) \ + { \ + if (wDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("WAL ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ + } \ } -#define wWarn(...) \ - { \ - if (wDebugFlag & DEBUG_WARN) { \ - taosPrintLog("WAL WARN ", 255, __VA_ARGS__); \ - } \ +#define wWarn(...) \ + { \ + if (wDebugFlag & DEBUG_WARN) { \ + taosPrintLog("WAL WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ + } \ } -#define wInfo(...) \ - { \ - if (wDebugFlag & DEBUG_INFO) { \ - taosPrintLog("WAL ", 255, __VA_ARGS__); \ - } \ +#define wInfo(...) \ + { \ + if (wDebugFlag & DEBUG_INFO) { \ + taosPrintLog("WAL ", DEBUG_INFO, 255, __VA_ARGS__); \ + } \ } -#define wDebug(...) \ - { \ - if (wDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); \ - } \ +#define wDebug(...) \ + { \ + if (wDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("WAL ", DEBUG_DEBUG, wDebugFlag, __VA_ARGS__); \ + } \ } -#define wTrace(...) \ - { \ - if (wDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); \ - } \ +#define wTrace(...) \ + { \ + if (wDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("WAL ", DEBUG_TRACE, wDebugFlag, __VA_ARGS__); \ + } \ } #define WAL_HEAD_VER 0 diff --git a/include/util/tlog.h b/include/util/tlog.h index 6e6795e9a2c6c564e8d5dc4fe0bd642401907141..d3ab9b0bfb76b566ee91101c2fc8fb7298ace2c4 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -22,9 +22,29 @@ extern "C" { #endif +typedef enum { + DEBUG_FATAL = 1, + DEBUG_ERROR = 1, + DEBUG_WARN = 2, + DEBUG_INFO = 2, + DEBUG_DEBUG = 4, + DEBUG_TRACE = 8, + DEBUG_DUMP = 16, + DEBUG_SCREEN = 64, + DEBUG_FILE = 128 +} ELogLevel; + +typedef void (*LogFp)(int64_t ts, ELogLevel level, const char *content); + +extern bool tsLogEmbedded; extern bool tsAsyncLog; extern int32_t tsNumOfLogLines; extern int32_t tsLogKeepDays; +extern LogFp tsLogFp; +extern int64_t tsNumOfErrorLogs; +extern int64_t tsNumOfInfoLogs; +extern int64_t tsNumOfDebugLogs; +extern int64_t tsNumOfTraceLogs; extern int32_t dDebugFlag; extern int32_t vDebugFlag; extern int32_t mDebugFlag; @@ -40,45 +60,33 @@ extern int32_t tsdbDebugFlag; extern int32_t tqDebugFlag; extern int32_t fsDebugFlag; -#define DEBUG_FATAL 1U -#define DEBUG_ERROR DEBUG_FATAL -#define DEBUG_WARN 2U -#define DEBUG_INFO DEBUG_WARN -#define DEBUG_DEBUG 4U -#define DEBUG_TRACE 8U -#define DEBUG_DUMP 16U -#define DEBUG_SCREEN 64U -#define DEBUG_FILE 128U - int32_t taosInitLog(const char *logName, int32_t maxFiles); void taosCloseLog(); void taosResetLog(); void taosSetAllDebugFlag(int32_t flag); void taosDumpData(uint8_t *msg, int32_t len); -void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) +void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) #ifdef __GNUC__ - __attribute__((format(printf, 3, 4))) + __attribute__((format(printf, 4, 5))) #endif ; -void taosPrintLongString(const char *flags, int32_t dflag, const char *format, ...) +void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) #ifdef __GNUC__ - __attribute__((format(printf, 3, 4))) + __attribute__((format(printf, 4, 5))) #endif ; -extern int8_t tscEmbeddedInUtil; - -#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }} -#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }} -#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }} -#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }} -#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }} -#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }} +#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }} +#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }} +#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", DEBUG_WARN, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }} +#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", DEBUG_INFO, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }} +#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", DEBUG_DEBUG, uDebugFlag, __VA_ARGS__); }} +#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", DEBUG_TRACE, uDebugFlag, __VA_ARGS__); }} -#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); } -#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); } +#define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); } +#define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); } #ifdef __cplusplus } diff --git a/source/client/inc/clientLog.h b/source/client/inc/clientLog.h index bfa2c0319b4b4afd11b0ee91b1efaa8b1f1b003b..d47edcd79535a3c8fc5d94aabd3bd8b08d0448f7 100644 --- a/source/client/inc/clientLog.h +++ b/source/client/inc/clientLog.h @@ -22,13 +22,13 @@ extern "C" { #include "tlog.h" -#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", cDebugFlag, __VA_ARGS__); }} while(0) -#define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", cDebugFlag, __VA_ARGS__); }} while(0) -#define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", cDebugFlag, __VA_ARGS__); }} while(0) -#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", 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 tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", cDebugFlag, __VA_ARGS__); }} while(0) +#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", DEBUG_FATAL, cDebugFlag, __VA_ARGS__); }} while(0) +#define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", DEBUG_ERROR, cDebugFlag, __VA_ARGS__); }} while(0) +#define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", DEBUG_WARN, cDebugFlag, __VA_ARGS__); }} while(0) +#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", DEBUG_INFO, cDebugFlag, __VA_ARGS__); }} while(0) +#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0) +#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", DEBUG_TRACE, cDebugFlag, __VA_ARGS__); }} while(0) +#define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0) #ifdef __cplusplus } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index ef6be6a3f39818a682082a82e42c040f87677654..a521e10cc79aa9e5c95ec89614a5439e012d85ea 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -478,10 +478,10 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi if (pCfg == NULL) return -1; if (tsc) { - tscEmbeddedInUtil = 0; + tsLogEmbedded = 0; if (taosAddClientLogCfg(pCfg) != 0) return -1; } else { - tscEmbeddedInUtil = 1; + tsLogEmbedded = 1; if (taosAddClientLogCfg(pCfg) != 0) return -1; if (taosAddServerLogCfg(pCfg) != 0) return -1; } diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index db90baff78b33b3c958eac1e1042b32c31c59b45..4ca6b97ad44d3e1fb21fe76cfdfa198def67552c 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -47,14 +47,12 @@ extern "C" { #include "vnode.h" #include "tfs.h" -extern int32_t dDebugFlag; - -#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }} -#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }} -#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }} -#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", 255, __VA_ARGS__); }} -#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }} -#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }} +#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} +#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EStat; typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType; diff --git a/source/dnode/mgmt/impl/test/sut/src/sut.cpp b/source/dnode/mgmt/impl/test/sut/src/sut.cpp index 00a79ebfd9b2d45ce6f6e2bc7f888f4f0522edba..2e38ea75137f4120b4611db8c6f133164e05cee2 100644 --- a/source/dnode/mgmt/impl/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/sut.cpp @@ -28,7 +28,7 @@ void Testbase::InitLog(const char* path) { wDebugFlag = 0; sDebugFlag = 0; tsdbDebugFlag = 0; - tscEmbeddedInUtil = 1; + tsLogEmbedded = 1; tsAsyncLog = 0; taosRemoveDir(path); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index bb2367ef728398ae049448afb42f544dccf71c90..91d37c4eedf5946432c2d366af46f36d08df2ec1 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -34,46 +34,6 @@ extern "C" { #endif -extern int32_t mDebugFlag; - -// mnode log function -#define mFatal(...) \ - { \ - if (mDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("MND FATAL ", 255, __VA_ARGS__); \ - } \ - } -#define mError(...) \ - { \ - if (mDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("MND ERROR ", 255, __VA_ARGS__); \ - } \ - } -#define mWarn(...) \ - { \ - if (mDebugFlag & DEBUG_WARN) { \ - taosPrintLog("MND WARN ", 255, __VA_ARGS__); \ - } \ - } -#define mInfo(...) \ - { \ - if (mDebugFlag & DEBUG_INFO) { \ - taosPrintLog("MND ", 255, __VA_ARGS__); \ - } \ - } -#define mDebug(...) \ - { \ - if (mDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); \ - } \ - } -#define mTrace(...) \ - { \ - if (mDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); \ - } \ - } - typedef enum { MND_AUTH_ACCT_START = 0, MND_AUTH_ACCT_USER, diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 39c9efb7627b0beb95ed99eef2a8e17f00f2b154..0fe24cd7575162a2ecb1bfe41e77ed6df49e2060 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -31,6 +31,13 @@ extern "C" { #endif +#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }} +#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }} + typedef int32_t (*MndMsgFp)(SMnodeMsg *pMsg); typedef int32_t (*MndInitFp)(SMnode *pMnode); typedef void (*MndCleanupFp)(SMnode *pMnode); diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index c99dff57e187f96461098c3edda0cb27688f93ba..d268b930519eea1e76df02b122887a270aaa7d8b 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -28,12 +28,12 @@ extern "C" { #endif -#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }} -#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }} -#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }} -#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }} -#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }} -#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }} +#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }} +#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }} #define SDB_MAX_SIZE (32 * 1024) diff --git a/source/dnode/vnode/src/inc/tqInt.h b/source/dnode/vnode/src/inc/tqInt.h index 30a83ca63446dbcf11448d5f06728353d6b97010..f41641385957d7a711490f3f2a30608f668ba2b4 100644 --- a/source/dnode/vnode/src/inc/tqInt.h +++ b/source/dnode/vnode/src/inc/tqInt.h @@ -25,43 +25,41 @@ extern "C" { #endif -extern int32_t tqDebugFlag; - -#define tqFatal(...) \ - { \ - if (tqDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("TQ FATAL ", 255, __VA_ARGS__); \ - } \ +#define tqFatal(...) \ + { \ + if (tqDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ + } \ } -#define tqError(...) \ - { \ - if (tqDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("TQ ERROR ", 255, __VA_ARGS__); \ - } \ +#define tqError(...) \ + { \ + if (tqDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ + } \ } -#define tqWarn(...) \ - { \ - if (tqDebugFlag & DEBUG_WARN) { \ - taosPrintLog("TQ WARN ", 255, __VA_ARGS__); \ - } \ +#define tqWarn(...) \ + { \ + if (tqDebugFlag & DEBUG_WARN) { \ + taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ + } \ } -#define tqInfo(...) \ - { \ - if (tqDebugFlag & DEBUG_INFO) { \ - taosPrintLog("TQ ", 255, __VA_ARGS__); \ - } \ +#define tqInfo(...) \ + { \ + if (tqDebugFlag & DEBUG_INFO) { \ + taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); \ + } \ } -#define tqDebug(...) \ - { \ - if (tqDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("TQ ", tqDebugFlag, __VA_ARGS__); \ - } \ +#define tqDebug(...) \ + { \ + if (tqDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); \ + } \ } -#define tqTrace(...) \ - { \ - if (tqDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("TQ ", tqDebugFlag, __VA_ARGS__); \ - } \ +#define tqTrace(...) \ + { \ + if (tqDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); \ + } \ } #define TQ_BUFFER_SIZE 8 diff --git a/source/dnode/vnode/src/inc/tsdbLog.h b/source/dnode/vnode/src/inc/tsdbLog.h index bde9b338a2b1e6cfd0a3408911ee4d84778ecf84..6ab17ec587263f922907e524bc7c42e7e3684d97 100644 --- a/source/dnode/vnode/src/inc/tsdbLog.h +++ b/source/dnode/vnode/src/inc/tsdbLog.h @@ -20,11 +20,11 @@ extern int32_t tsdbDebugFlag; -#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }} while(0) -#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", 255, __VA_ARGS__); }} while(0) -#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }} while(0) -#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", 255, __VA_ARGS__); }} while(0) -#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0) -#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) #endif /* _TD_TSDB_LOG_H_ */ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 75088687a810ea461daaa04793005518c0e659b7..6f4f0049e3b728103122cbf71d9b16f37bd88c53 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -88,44 +88,41 @@ int vnodeScheduleTask(SVnodeTask* task); int32_t vnodePutReqToVQueryQ(SVnode* pVnode, struct SRpcMsg* pReq); void vnodeSendReqToDnode(SVnode* pVnode, struct SEpSet* epSet, struct SRpcMsg* pReq); -// For Log -extern int32_t vDebugFlag; - -#define vFatal(...) \ - do { \ - if (vDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("VND FATAL ", 255, __VA_ARGS__); \ - } \ +#define vFatal(...) \ + do { \ + if (vDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ + } \ } while (0) -#define vError(...) \ - do { \ - if (vDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("VND ERROR ", 255, __VA_ARGS__); \ - } \ +#define vError(...) \ + do { \ + if (vDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ + } \ } while (0) -#define vWarn(...) \ - do { \ - if (vDebugFlag & DEBUG_WARN) { \ - taosPrintLog("VND WARN ", 255, __VA_ARGS__); \ - } \ +#define vWarn(...) \ + do { \ + if (vDebugFlag & DEBUG_WARN) { \ + taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ + } \ } while (0) -#define vInfo(...) \ - do { \ - if (vDebugFlag & DEBUG_INFO) { \ - taosPrintLog("VND ", 255, __VA_ARGS__); \ - } \ +#define vInfo(...) \ + do { \ + if (vDebugFlag & DEBUG_INFO) { \ + taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); \ + } \ } while (0) -#define vDebug(...) \ - do { \ - if (vDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("VND ", tsdbDebugFlag, __VA_ARGS__); \ - } \ +#define vDebug(...) \ + do { \ + if (vDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("VND ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define vTrace(...) \ - do { \ - if (vDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("VND ", tsdbDebugFlag, __VA_ARGS__); \ - } \ +#define vTrace(...) \ + do { \ + if (vDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("VND ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); \ + } \ } while (0) // vnodeCfg.h diff --git a/source/libs/index/inc/indexInt.h b/source/libs/index/inc/indexInt.h index 0fcaf11087ef3e380b07974f273543b78d3aa5de..6cb5142dd83da3c3d5f3153a5d8a34bb82d35256 100644 --- a/source/libs/index/inc/indexInt.h +++ b/source/libs/index/inc/indexInt.h @@ -125,41 +125,41 @@ int32_t indexSerialCacheKey(ICacheKey* key, char* buf); // int32_t indexSerialKey(ICacheKey* key, char* buf); // int32_t indexSerialTermKey(SIndexTerm* itm, char* buf); -#define indexFatal(...) \ - do { \ - if (sDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("index FATAL ", 255, __VA_ARGS__); \ - } \ +#define indexFatal(...) \ + do { \ + if (sDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("index FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ + } \ } while (0) -#define indexError(...) \ - do { \ - if (sDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("index ERROR ", 255, __VA_ARGS__); \ - } \ +#define indexError(...) \ + do { \ + if (sDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("index ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ + } \ } while (0) -#define indexWarn(...) \ - do { \ - if (sDebugFlag & DEBUG_WARN) { \ - taosPrintLog("index WARN ", 255, __VA_ARGS__); \ - } \ +#define indexWarn(...) \ + do { \ + if (sDebugFlag & DEBUG_WARN) { \ + taosPrintLog("index WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ + } \ } while (0) -#define indexInfo(...) \ - do { \ - if (sDebugFlag & DEBUG_INFO) { \ - taosPrintLog("index ", 255, __VA_ARGS__); \ - } \ +#define indexInfo(...) \ + do { \ + if (sDebugFlag & DEBUG_INFO) { \ + taosPrintLog("index ", DEBUG_INFO, 255, __VA_ARGS__); \ + } \ } while (0) -#define indexDebug(...) \ - do { \ - if (sDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("index ", sDebugFlag, __VA_ARGS__); \ - } \ +#define indexDebug(...) \ + do { \ + if (sDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("index ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); \ + } \ } while (0) -#define indexTrace(...) \ - do { \ - if (sDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("index ", sDebugFlag, __VA_ARGS__); \ - } \ +#define indexTrace(...) \ + do { \ + if (sDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("index ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); \ + } \ } while (0) #define INDEX_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0) diff --git a/source/libs/monitor/inc/monInt.h b/source/libs/monitor/inc/monInt.h index 61f9980e4e3133469869e1fb7f649b2aa33ec1cc..ca5aaf0a388826d0ba4acd329296337d5e491a0e 100644 --- a/source/libs/monitor/inc/monInt.h +++ b/source/libs/monitor/inc/monInt.h @@ -23,18 +23,24 @@ #include "tjson.h" typedef struct { - SRWLatch lock; - SArray *logs; // array of SMonLogItem - int32_t maxLogs; - const char *server; - uint16_t port; -} SMonitor; + int64_t ts; + ELogLevel level; + char content[MON_LOG_LEN]; +} SMonLogItem; typedef struct SMonInfo { SArray *logs; // array of SMonLogItem SJson *pJson; } SMonInfo; +typedef struct { + pthread_rwlock_t rwlock; + SArray *logs; // array of SMonLogItem + int32_t maxLogs; + const char *server; + uint16_t port; +} SMonitor; + #ifdef __cplusplus } #endif diff --git a/source/libs/monitor/src/monitor.c b/source/libs/monitor/src/monitor.c index 949fe3e5e7591938288e278048a1146b928d32ac..a50b8c3e90b56db1acbe8cfad9d2ab9c238b72d7 100644 --- a/source/libs/monitor/src/monitor.c +++ b/source/libs/monitor/src/monitor.c @@ -22,6 +22,21 @@ static SMonitor tsMonitor = {0}; +void monRecordLog(int64_t ts, ELogLevel level, const char *content) { + pthread_rwlock_rdlock(&tsMonitor.rwlock); + int32_t size = taosArrayGetSize(tsMonitor.logs); + if (size >= tsMonitor.maxLogs) { + uInfo("too many logs for monitor"); + } else { + SMonLogItem item = {.ts = ts, .level = level}; + SMonLogItem *pItem = taosArrayPush(tsMonitor.logs, &item); + if (pItem != NULL) { + tstrncpy(pItem->content, content, sizeof(item.content)); + } + } + pthread_rwlock_unlock(&tsMonitor.rwlock); +} + int32_t monInit(const SMonCfg *pCfg) { tsMonitor.logs = taosArrayInit(16, sizeof(SMonLogItem)); if (tsMonitor.logs == NULL) { @@ -32,24 +47,15 @@ int32_t monInit(const SMonCfg *pCfg) { tsMonitor.maxLogs = pCfg->maxLogs; tsMonitor.server = pCfg->server; tsMonitor.port = pCfg->port; - taosInitRWLatch(&tsMonitor.lock); + tsLogFp = monRecordLog; + pthread_rwlock_init(&tsMonitor.rwlock, NULL); return 0; } void monCleanup() { taosArrayDestroy(tsMonitor.logs); tsMonitor.logs = NULL; -} - -void monAddLogItem(SMonLogItem *pItem) { - taosWLockLatch(&tsMonitor.lock); - int32_t size = taosArrayGetSize(tsMonitor.logs); - if (size >= tsMonitor.maxLogs) { - uInfo("too many logs for monitor"); - } else { - taosArrayPush(tsMonitor.logs, pItem); - } - taosWUnLockLatch(&tsMonitor.lock); + pthread_rwlock_wrlock(&tsMonitor.rwlock); } SMonInfo *monCreateMonitorInfo() { @@ -59,10 +65,10 @@ SMonInfo *monCreateMonitorInfo() { return NULL; } - taosWLockLatch(&tsMonitor.lock); + pthread_rwlock_wrlock(&tsMonitor.rwlock); pMonitor->logs = taosArrayDup(tsMonitor.logs); taosArrayClear(tsMonitor.logs); - taosWUnLockLatch(&tsMonitor.lock); + pthread_rwlock_unlock(&tsMonitor.rwlock); pMonitor->pJson = tjsonCreateObject(); if (pMonitor->pJson == NULL || pMonitor->logs == NULL) { @@ -270,15 +276,15 @@ void monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) { tjsonAddDoubleToObject(pTempdirJson, "total", pInfo->tempdir.size.total); } -static const char *monLogLevelStr(EMonLogLevel level) { +static const char *monLogLevelStr(ELogLevel level) { switch (level) { - case MON_LEVEL_ERROR: + case DEBUG_ERROR: return "error"; - case MON_LEVEL_INFO: + case DEBUG_INFO: return "info"; - case MON_LEVEL_DEBUG: + case DEBUG_DEBUG: return "debug"; - case MON_LEVEL_TRACE: + case DEBUG_TRACE: return "trace"; default: return "undefine"; @@ -318,25 +324,25 @@ static void monSetLogInfo(SMonInfo *pMonitor) { SJson *pLogError = tjsonCreateObject(); if (pLogError == NULL) return; tjsonAddStringToObject(pLogError, "level", "error"); - tjsonAddDoubleToObject(pLogError, "total", 1); + tjsonAddDoubleToObject(pLogError, "total", tsNumOfErrorLogs); if (tjsonAddItemToArray(pSummaryJson, pLogError) != 0) tjsonDelete(pLogError); SJson *pLogInfo = tjsonCreateObject(); if (pLogInfo == NULL) return; tjsonAddStringToObject(pLogInfo, "level", "info"); - tjsonAddDoubleToObject(pLogInfo, "total", 1); + tjsonAddDoubleToObject(pLogInfo, "total", tsNumOfInfoLogs); if (tjsonAddItemToArray(pSummaryJson, pLogInfo) != 0) tjsonDelete(pLogInfo); SJson *pLogDebug = tjsonCreateObject(); if (pLogDebug == NULL) return; tjsonAddStringToObject(pLogDebug, "level", "debug"); - tjsonAddDoubleToObject(pLogDebug, "total", 1); + tjsonAddDoubleToObject(pLogDebug, "total", tsNumOfDebugLogs); if (tjsonAddItemToArray(pSummaryJson, pLogDebug) != 0) tjsonDelete(pLogDebug); SJson *pLogTrace = tjsonCreateObject(); if (pLogTrace == NULL) return; tjsonAddStringToObject(pLogTrace, "level", "trace"); - tjsonAddDoubleToObject(pLogTrace, "total", 1); + tjsonAddDoubleToObject(pLogTrace, "total", tsNumOfTraceLogs); if (tjsonAddItemToArray(pSummaryJson, pLogTrace) != 0) tjsonDelete(pLogTrace); } diff --git a/source/libs/monitor/test/monTest.cpp b/source/libs/monitor/test/monTest.cpp index 49abd4803ac314acf68cabf5a06efff22e3c6d80..3eaab45e3e6d21af7a74e4bfb6735f250a023577 100644 --- a/source/libs/monitor/test/monTest.cpp +++ b/source/libs/monitor/test/monTest.cpp @@ -193,37 +193,14 @@ void MonitorTest::GetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) { } void MonitorTest::AddLogInfo1() { - SMonLogItem log1 = {0}; - log1.ts = taosGetTimestampMs(); - log1.level = MON_LEVEL_INFO; - strcpy(log1.content, "1 -------------------------- a"); - monAddLogItem(&log1); - - SMonLogItem log2 = {0}; - log2.ts = taosGetTimestampMs(); - log2.level = MON_LEVEL_ERROR; - strcpy(log2.content, "1 ------------------------ b"); - monAddLogItem(&log2); - - SMonLogItem log3 = {0}; - log3.ts = taosGetTimestampMs(); - log3.level = MON_LEVEL_DEBUG; - strcpy(log3.content, "1 ------- c"); - monAddLogItem(&log3); + monRecordLog(taosGetTimestampMs(), DEBUG_INFO, "1 -------------------------- a"); + monRecordLog(taosGetTimestampMs(), DEBUG_ERROR, "1 ------------------------ b"); + monRecordLog(taosGetTimestampMs(), DEBUG_DEBUG, "1 ------- c"); } void MonitorTest::AddLogInfo2() { - SMonLogItem log1; - log1.ts = taosGetTimestampMs(); - log1.level = MON_LEVEL_ERROR; - strcpy(log1.content, "2 ------- a"); - monAddLogItem(&log1); - - SMonLogItem log2; - log2.ts = taosGetTimestampMs(); - log2.level = MON_LEVEL_ERROR; - strcpy(log2.content, "2 ------- b"); - monAddLogItem(&log2); + monRecordLog(taosGetTimestampMs(), DEBUG_ERROR, "2 ------- a"); + monRecordLog(taosGetTimestampMs(), DEBUG_ERROR, "2 ------- b"); } TEST_F(MonitorTest, 01_Full) { diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index aedb9662b1e55880932b15369743de39bde7f4e7..e276bbd23495c7db8c94dad194dc0468b66e6721 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -29,43 +29,41 @@ extern "C" { #include "tlog.h" #include "ttimer.h" -extern int32_t sDebugFlag; - -#define sFatal(...) \ - { \ - if (sDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("SYN FATAL ", sDebugFlag, __VA_ARGS__); \ - } \ +#define sFatal(...) \ + { \ + if (sDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ + } \ } -#define sError(...) \ - { \ - if (sDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("SYN ERROR ", sDebugFlag, __VA_ARGS__); \ - } \ +#define sError(...) \ + { \ + if (sDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ + } \ } -#define sWarn(...) \ - { \ - if (sDebugFlag & DEBUG_WARN) { \ - taosPrintLog("SYN WARN ", sDebugFlag, __VA_ARGS__); \ - } \ +#define sWarn(...) \ + { \ + if (sDebugFlag & DEBUG_WARN) { \ + taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ + } \ } -#define sInfo(...) \ - { \ - if (sDebugFlag & DEBUG_INFO) { \ - taosPrintLog("SYN INFO ", sDebugFlag, __VA_ARGS__); \ - } \ +#define sInfo(...) \ + { \ + if (sDebugFlag & DEBUG_INFO) { \ + taosPrintLog("SYN INFO ", DEBUG_INFO, 255, __VA_ARGS__); \ + } \ } -#define sDebug(...) \ - { \ - if (sDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("SYN DEBUG ", sDebugFlag, __VA_ARGS__); \ - } \ +#define sDebug(...) \ + { \ + if (sDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("SYN DEBUG ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); \ + } \ } -#define sTrace(...) \ - { \ - if (sDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("SYN TRACE ", sDebugFlag, __VA_ARGS__); \ - } \ +#define sTrace(...) \ + { \ + if (sDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("SYN TRACE ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); \ + } \ } struct SRaft; diff --git a/source/libs/tfs/inc/tfsInt.h b/source/libs/tfs/inc/tfsInt.h index cfc246f07b98446f8b59d78e7ad2d8fa1f0c147a..913f34d6c201b54f396493e28c4459037a614057 100644 --- a/source/libs/tfs/inc/tfsInt.h +++ b/source/libs/tfs/inc/tfsInt.h @@ -25,15 +25,13 @@ #include "thash.h" #include "tlog.h" -extern int32_t fsDebugFlag; - // For debug purpose -#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("TFS FATAL ", 255, __VA_ARGS__); }} -#define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("TFS ERROR ", 255, __VA_ARGS__); }} -#define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("TFS WARN ", 255, __VA_ARGS__); }} -#define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("TFS ", 255, __VA_ARGS__); }} -#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("TFS ", fsDebugFlag, __VA_ARGS__); }} -#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("TFS ", fsDebugFlag, __VA_ARGS__); }} +#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("TFS FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("TFS ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("TFS WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("TFS ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("TFS ", DEBUG_DEBUG, fsDebugFlag, __VA_ARGS__); }} +#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("TFS ", DEBUG_TRACE, fsDebugFlag, __VA_ARGS__); }} typedef struct { int32_t level; diff --git a/source/libs/transport/inc/rpcLog.h b/source/libs/transport/inc/rpcLog.h index 621504091c653f63d2c09a71535700299b58a285..a5db866932c5228741de88b3a165def88950f238 100644 --- a/source/libs/transport/inc/rpcLog.h +++ b/source/libs/transport/inc/rpcLog.h @@ -22,44 +22,41 @@ extern "C" { #include "tlog.h" -extern int32_t rpcDebugFlag; - -// rpcDebugFlag = 143 -#define tFatal(...) \ - { \ - if (rpcDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("RPC FATAL ", rpcDebugFlag, __VA_ARGS__); \ - } \ +#define tFatal(...) \ + { \ + if (rpcDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("RPC FATAL ", DEBUG_FATAL, rpcDebugFlag, __VA_ARGS__); \ + } \ } -#define tError(...) \ - { \ - if (rpcDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("RPC ERROR ", rpcDebugFlag, __VA_ARGS__); \ - } \ +#define tError(...) \ + { \ + if (rpcDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("RPC ERROR ", DEBUG_ERROR, rpcDebugFlag, __VA_ARGS__); \ + } \ } -#define tWarn(...) \ - { \ - if (rpcDebugFlag & DEBUG_WARN) { \ - taosPrintLog("RPC WARN ", rpcDebugFlag, __VA_ARGS__); \ - } \ +#define tWarn(...) \ + { \ + if (rpcDebugFlag & DEBUG_WARN) { \ + taosPrintLog("RPC WARN ", DEBUG_WARN, rpcDebugFlag, __VA_ARGS__); \ + } \ } -#define tInfo(...) \ - { \ - if (rpcDebugFlag & DEBUG_INFO) { \ - taosPrintLog("RPC ", rpcDebugFlag, __VA_ARGS__); \ - } \ +#define tInfo(...) \ + { \ + if (rpcDebugFlag & DEBUG_INFO) { \ + taosPrintLog("RPC ", DEBUG_INFO, rpcDebugFlag, __VA_ARGS__); \ + } \ } -#define tDebug(...) \ - { \ - if (rpcDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("RPC ", rpcDebugFlag, __VA_ARGS__); \ - } \ +#define tDebug(...) \ + { \ + if (rpcDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("RPC ", DEBUG_DEBUG, rpcDebugFlag, __VA_ARGS__); \ + } \ } -#define tTrace(...) \ - { \ - if (rpcDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("RPC ", rpcDebugFlag, __VA_ARGS__); \ - } \ +#define tTrace(...) \ + { \ + if (rpcDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("RPC ", DEBUG_TRACE, rpcDebugFlag, __VA_ARGS__); \ + } \ } #define tDump(x, y) \ { \ diff --git a/source/libs/transport/test/transUT.cc b/source/libs/transport/test/transUT.cc index d5e0b65d41e40d13a870808f54e60e26faa51cc1..5edddb006bba8dcc24af4f94996eece4a0e4f5dd 100644 --- a/source/libs/transport/test/transUT.cc +++ b/source/libs/transport/test/transUT.cc @@ -148,7 +148,7 @@ class TransObj { wDebugFlag = 0; sDebugFlag = 0; tsdbDebugFlag = 0; - tscEmbeddedInUtil = 1; + tsLogEmbedded = 1; tsAsyncLog = 0; std::string path = "/tmp/transport"; diff --git a/source/util/src/thttp.c b/source/util/src/thttp.c index adf29b1aa96e91e51e3e4515d684ffbf76d4c273..0737f67ed1d69b215606ac7a1713ae5573bdedb0 100644 --- a/source/util/src/thttp.c +++ b/source/util/src/thttp.c @@ -63,7 +63,7 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, const char* pCont, goto SEND_OVER; } - uInfo("send http to %s:%u, len:%d content: %s", server, port, contLen, pCont); + uTrace("send http to %s:%u, len:%d content: %s", server, port, contLen, pCont); code = 0; SEND_OVER: diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index d821e0440b814f28e6e9274261f21fffac10b00d..f3457da5b0f733cabab89e91043638a2a9fd905b 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -66,13 +66,18 @@ typedef struct { static int8_t tsLogInited = 0; static SLogObj tsLogObj = {.fileNum = 1}; +static int64_t tsAsyncLogLostLines = 0; +static int32_t tsWriteInterval = LOG_DEFAULT_INTERVAL; -int8_t tscEmbeddedInUtil = 0; -int32_t tsLogKeepDays = 0; +bool tsLogEmbedded = 0; bool tsAsyncLog = true; int32_t tsNumOfLogLines = 10000000; -int64_t tsAsyncLogLostLines = 0; -int32_t tsWriteInterval = LOG_DEFAULT_INTERVAL; +int32_t tsLogKeepDays = 0; +LogFp tsLogFp = NULL; +int64_t tsNumOfErrorLogs = 0; +int64_t tsNumOfInfoLogs = 0; +int64_t tsNumOfDebugLogs = 0; +int64_t tsNumOfTraceLogs = 0; // log int32_t dDebugFlag = 135; @@ -372,7 +377,27 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { return 0; } -void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { +static void taosUpdateLogNums(ELogLevel level) { + switch (level) { + case DEBUG_ERROR: + atomic_add_fetch_64(&tsNumOfErrorLogs, 1); + break; + case DEBUG_INFO: + atomic_add_fetch_64(&tsNumOfInfoLogs, 1); + break; + case DEBUG_DEBUG: + atomic_add_fetch_64(&tsNumOfDebugLogs, 1); + break; + case DEBUG_DUMP: + case DEBUG_TRACE: + atomic_add_fetch_64(&tsNumOfTraceLogs, 1); + break; + default: + break; + } +} + +void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) { if (!osLogSpaceAvailable()) return; va_list argpointer; @@ -410,6 +435,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { buffer[len] = 0; if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->pFile != NULL) { + taosUpdateLogNums(level); if (tsAsyncLog) { taosPushLogBuffer(tsLogObj.logHandle, buffer, len); } else { @@ -423,11 +449,14 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { } } - if (dflag & DEBUG_SCREEN) write(1, buffer, (uint32_t)len); + if (dflag & DEBUG_SCREEN) { + write(1, buffer, (uint32_t)len); + } } void taosDumpData(unsigned char *msg, int32_t len) { if (!osLogSpaceAvailable()) return; + taosUpdateLogNums(DEBUG_DUMP); char temp[256]; int32_t i, pos = 0, c = 0; @@ -449,7 +478,7 @@ void taosDumpData(unsigned char *msg, int32_t len) { taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos); } -void taosPrintLongString(const char *flags, int32_t dflag, const char *format, ...) { +void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) { if (!osLogSpaceAvailable()) return; va_list argpointer; @@ -477,6 +506,7 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . buffer[len] = 0; if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->pFile != NULL) { + taosUpdateLogNums(level); if (tsAsyncLog) { taosPushLogBuffer(tsLogObj.logHandle, buffer, len); } else { @@ -490,7 +520,9 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . } } - if (dflag & DEBUG_SCREEN) write(1, buffer, (uint32_t)len); + if (dflag & DEBUG_SCREEN) { + write(1, buffer, (uint32_t)len); + } } static void taosCloseLogByFd(TdFilePtr pFile) { diff --git a/source/util/src/ttimer.c b/source/util/src/ttimer.c index abb42ef28d6d0135cce72ac494e21b5b85d51418..72c18518e39894eb6d370051cfc8605c85a0eba3 100644 --- a/source/util/src/ttimer.c +++ b/source/util/src/ttimer.c @@ -19,41 +19,41 @@ #include "tlog.h" #include "tsched.h" -#define tmrFatal(...) \ - { \ - if (tmrDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("TMR FATAL ", tmrDebugFlag, __VA_ARGS__); \ - } \ - } -#define tmrError(...) \ - { \ - if (tmrDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("TMR ERROR ", tmrDebugFlag, __VA_ARGS__); \ - } \ - } -#define tmrWarn(...) \ - { \ - if (tmrDebugFlag & DEBUG_WARN) { \ - taosPrintLog("TMR WARN ", tmrDebugFlag, __VA_ARGS__); \ - } \ - } -#define tmrInfo(...) \ - { \ - if (tmrDebugFlag & DEBUG_INFO) { \ - taosPrintLog("TMR ", tmrDebugFlag, __VA_ARGS__); \ - } \ - } -#define tmrDebug(...) \ - { \ - if (tmrDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("TMR ", tmrDebugFlag, __VA_ARGS__); \ - } \ - } -#define tmrTrace(...) \ - { \ - if (tmrDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("TMR ", tmrDebugFlag, __VA_ARGS__); \ - } \ +#define tmrFatal(...) \ + { \ + if (tmrDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("TMR FATAL ", DEBUG_FATAL, tmrDebugFlag, __VA_ARGS__); \ + } \ + } +#define tmrError(...) \ + { \ + if (tmrDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("TMR ERROR ", DEBUG_ERROR, tmrDebugFlag, __VA_ARGS__); \ + } \ + } +#define tmrWarn(...) \ + { \ + if (tmrDebugFlag & DEBUG_WARN) { \ + taosPrintLog("TMR WARN ", DEBUG_WARN, tmrDebugFlag, __VA_ARGS__); \ + } \ + } +#define tmrInfo(...) \ + { \ + if (tmrDebugFlag & DEBUG_INFO) { \ + taosPrintLog("TMR ", DEBUG_INFO, tmrDebugFlag, __VA_ARGS__); \ + } \ + } +#define tmrDebug(...) \ + { \ + if (tmrDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("TMR ", DEBUG_DEBUG, tmrDebugFlag, __VA_ARGS__); \ + } \ + } +#define tmrTrace(...) \ + { \ + if (tmrDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("TMR ", DEBUG_TRACE, tmrDebugFlag, __VA_ARGS__); \ + } \ } #define TIMER_STATE_WAITING 0