TDengine/include/util/tlog.h

136 lines
4.7 KiB
C
Raw Normal View History

2021-09-23 07:50:12 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-02-28 07:19:00 +00:00
#ifndef _TD_UTIL_LOG_H_
#define _TD_UTIL_LOG_H_
2021-09-23 07:50:12 +00:00
2021-11-23 07:46:23 +00:00
#include "os.h"
2021-09-23 07:50:12 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-03-04 06:34:35 +00:00
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;
2022-03-04 05:53:50 +00:00
2022-03-04 07:15:29 +00:00
typedef void (*LogFp)(int64_t ts, ELogLevel level, const char *content);
2022-03-04 05:53:50 +00:00
extern bool tsLogEmbedded;
2022-02-23 02:35:53 +00:00
extern bool tsAsyncLog;
2022-12-07 14:24:47 +00:00
extern bool tsAssert;
2021-09-30 13:21:51 +00:00
extern int32_t tsNumOfLogLines;
extern int32_t tsLogKeepDays;
2022-03-04 07:15:29 +00:00
extern LogFp tsLogFp;
2022-03-04 05:53:50 +00:00
extern int64_t tsNumOfErrorLogs;
extern int64_t tsNumOfInfoLogs;
extern int64_t tsNumOfDebugLogs;
extern int64_t tsNumOfTraceLogs;
2021-09-30 13:21:51 +00:00
extern int32_t dDebugFlag;
extern int32_t vDebugFlag;
extern int32_t mDebugFlag;
extern int32_t cDebugFlag;
extern int32_t jniDebugFlag;
extern int32_t tmrDebugFlag;
extern int32_t uDebugFlag;
extern int32_t rpcDebugFlag;
extern int32_t qDebugFlag;
2023-09-20 10:18:31 +00:00
extern int32_t stDebugFlag;
2021-09-30 13:21:51 +00:00
extern int32_t wDebugFlag;
extern int32_t sDebugFlag;
extern int32_t tsdbDebugFlag;
2021-12-20 10:42:31 +00:00
extern int32_t tqDebugFlag;
2022-02-23 02:35:53 +00:00
extern int32_t fsDebugFlag;
2022-04-19 13:10:03 +00:00
extern int32_t metaDebugFlag;
2022-07-08 07:20:15 +00:00
extern int32_t udfDebugFlag;
extern int32_t smaDebugFlag;
2022-05-24 07:17:14 +00:00
extern int32_t idxDebugFlag;
2022-07-26 09:46:47 +00:00
extern int32_t tdbDebugFlag;
2023-11-15 03:50:14 +00:00
extern int32_t sndDebugFlag;
2024-01-03 11:57:22 +00:00
extern int32_t simDebugFlag;
2021-12-14 07:24:21 +00:00
2022-02-23 02:35:53 +00:00
int32_t taosInitLog(const char *logName, int32_t maxFiles);
2021-09-23 07:50:12 +00:00
void taosCloseLog();
void taosResetLog();
2022-02-27 02:32:15 +00:00
void taosDumpData(uint8_t *msg, int32_t len);
2021-09-23 07:50:12 +00:00
2022-03-04 06:34:35 +00:00
void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...)
2021-09-23 07:50:12 +00:00
#ifdef __GNUC__
2022-03-04 06:34:35 +00:00
__attribute__((format(printf, 4, 5)))
2021-09-23 07:50:12 +00:00
#endif
;
2022-03-04 06:34:35 +00:00
void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...)
2021-09-23 07:50:12 +00:00
#ifdef __GNUC__
2022-03-04 06:34:35 +00:00
__attribute__((format(printf, 4, 5)))
2021-09-23 07:50:12 +00:00
#endif
;
void taosPrintSlowLog(const char *format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 1, 2)))
#endif
;
bool taosAssertDebug(bool condition, const char *file, int32_t line, bool core, const char *format, ...);
2022-12-30 03:14:31 +00:00
bool taosAssertRelease(bool condition);
2023-01-03 01:47:01 +00:00
// Disable all asserts that may compromise the performance.
#if defined DISABLE_ASSERT
#define ASSERT(condition)
2023-02-24 06:41:23 +00:00
#define ASSERTS(condition, ...) (0)
2023-01-03 01:47:01 +00:00
#else
#define ASSERT_CORE(condition, ...) \
((condition) ? false : taosAssertDebug(condition, __FILE__, __LINE__, 1, __VA_ARGS__))
#define ASSERTS(condition, ...) ((condition) ? false : taosAssertDebug(condition, __FILE__, __LINE__, 0, __VA_ARGS__))
2022-12-30 03:14:31 +00:00
#ifdef NDEBUG
#define ASSERT(condition) taosAssertRelease(condition)
#else
2023-02-24 06:41:23 +00:00
#define ASSERT(condition) ASSERTS(condition, "assert info not provided")
2022-12-30 03:14:31 +00:00
#endif
2023-01-03 01:47:01 +00:00
#endif
2022-12-07 14:24:47 +00:00
void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo);
void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd);
void taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile);
2022-12-23 01:22:14 +00:00
2022-04-19 13:10:03 +00:00
// clang-format off
2022-03-04 06:34:35 +00:00
#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 uDebugL(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLongString("UTL ", DEBUG_DEBUG, uDebugFlag, __VA_ARGS__); }}
2023-10-23 08:59:54 +00:00
#define uInfoL(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLongString("UTL ", DEBUG_INFO, uDebugFlag, __VA_ARGS__); }}
2022-02-27 03:04:39 +00:00
2022-03-04 06:34:35 +00:00
#define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
#define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); }
2022-04-19 13:10:03 +00:00
// clang-format on
2023-02-24 06:41:23 +00:00
// #define BUF_PAGE_DEBUG
2021-09-23 07:50:12 +00:00
#ifdef __cplusplus
}
#endif
2022-02-28 07:19:00 +00:00
#endif /*_TD_UTIL_LOG_H_*/