Coverage Report

Created: 2026-05-23 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tdengine/include/util/tlog.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15
16
#ifndef _TD_UTIL_LOG_H_
17
#define _TD_UTIL_LOG_H_
18
19
#include "os.h"
20
21
#ifdef __cplusplus
22
extern "C" {
23
#endif
24
25
typedef enum {
26
  DEBUG_FATAL = 1,
27
  DEBUG_ERROR = 1,
28
  DEBUG_WARN = 2,
29
  DEBUG_INFO = 2,
30
  DEBUG_DEBUG = 4,
31
  DEBUG_TRACE = 8,
32
  DEBUG_DUMP = 16,
33
  DEBUG_SCREEN = 64,
34
  DEBUG_FILE = 128
35
} ELogLevel;
36
37
typedef enum {
38
  LOG_MODE_TAOSC = 1,
39
  LOG_MODE_TAOSD = 2
40
} ELogMode;
41
42
typedef void (*LogFp)(int64_t ts, ELogLevel level, const char *content);
43
44
extern bool    tsLogEmbedded;
45
extern bool    tsAsyncLog;
46
extern bool    tsAssert;
47
extern int32_t tsNumOfLogLines;
48
extern int32_t tsLogKeepDays;
49
extern char   *tsLogOutput;
50
extern LogFp   tsLogFp;
51
extern int64_t tsNumOfErrorLogs;
52
extern int64_t tsNumOfInfoLogs;
53
extern int64_t tsNumOfDebugLogs;
54
extern int64_t tsNumOfTraceLogs;
55
extern int32_t dDebugFlag;
56
extern int32_t vDebugFlag;
57
extern int32_t mDebugFlag;
58
extern int32_t cDebugFlag;
59
extern int32_t jniDebugFlag;
60
extern int32_t tmrDebugFlag;
61
extern int32_t uDebugFlag;
62
extern int32_t rpcDebugFlag;
63
extern int32_t qDebugFlag;
64
extern int32_t stDebugFlag;
65
extern int32_t wDebugFlag;
66
extern int32_t azDebugFlag;
67
extern int32_t tssDebugFlag;
68
extern int32_t sDebugFlag;
69
extern int32_t tsdbDebugFlag;
70
extern int32_t tqDebugFlag;
71
extern int32_t fsDebugFlag;
72
extern int32_t metaDebugFlag;
73
extern int32_t udfDebugFlag;
74
extern int32_t smaDebugFlag;
75
extern int32_t idxDebugFlag;
76
extern int32_t tdbDebugFlag;
77
extern int32_t sndDebugFlag;
78
extern int32_t bndDebugFlag;
79
extern int32_t xndDebugFlag;
80
extern int32_t simDebugFlag;
81
extern int32_t bseDebugFlag;
82
83
extern int32_t tqClientDebugFlag;
84
int32_t        taosInitLogOutput(const char **ppLogName);
85
int32_t        taosInitLog(const char *logName, int32_t maxFiles, bool tsc);
86
void           taosCloseLog();
87
void           taosResetLog();
88
void           taosDumpData(uint8_t *msg, int32_t len);
89
void           taosSetNoNewFile();
90
91
// Fast uint64_t to string conversion, equivalent to sprintf(buf, "%lu", val) but with 10x better performance.
92
char *u64toaFastLut(uint64_t val, char *buf);
93
94
void taosPrintLog(const char *flags, int32_t level, int32_t dflag, const char *format, ...)
95
#ifdef __GNUC__
96
    __attribute__((format(printf, 4, 5)))
97
#endif
98
    ;
99
100
void taosPrintLongString(const char *flags, int32_t level, int32_t dflag, const char *format, ...)
101
#ifdef __GNUC__
102
    __attribute__((format(printf, 4, 5)))
103
#endif
104
    ;
105
106
void taosPrintSlowLog(const char *format, ...)
107
#ifdef __GNUC__
108
    __attribute__((format(printf, 1, 2)))
109
#endif
110
    ;
111
112
bool taosAssertDebug(bool condition, const char *file, int32_t line, bool core, const char *format, ...);
113
bool taosAssertRelease(bool condition);
114
115
// Disable all asserts that may compromise the performance.
116
#if defined DISABLE_ASSERT
117
#define ASSERT(condition)
118
#define ASSERTS(condition, ...) (0)
119
#else
120
#define ASSERT_CORE(condition, ...) \
121
  ((condition) ? false : taosAssertDebug(condition, __FILE__, __LINE__, 1, __VA_ARGS__))
122
#define ASSERTS(condition, ...) ((condition) ? false : taosAssertDebug(condition, __FILE__, __LINE__, 0, __VA_ARGS__))
123
#ifdef NDEBUG
124
#define ASSERT(condition) taosAssertRelease(condition)
125
#else
126
#define ASSERT(condition) ASSERTS(condition, "assert info not provided")
127
#endif
128
#endif
129
130
void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo);
131
void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd);
132
void taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile);
133
134
int32_t initCrashLogWriter();
135
void    checkAndPrepareCrashInfo();
136
bool    reportThreadSetQuit();
137
void    writeCrashLogToFile(int signum, void *sigInfo, char *nodeType, int64_t clusterId, int64_t startTime);
138
139
// clang-format off
140
0
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL ", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
141
0
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
142
0
#define uWarn(...)  { if (uDebugFlag & DEBUG_WARN)  { taosPrintLog("UTL WARN  ", DEBUG_WARN,  tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
143
0
#define uInfo(...)  { if (uDebugFlag & DEBUG_INFO)  { taosPrintLog("UTL INFO  ", DEBUG_INFO,  tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
144
0
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL DEBUG ", DEBUG_DEBUG, uDebugFlag,                       __VA_ARGS__); }}
145
0
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL TRACE ", DEBUG_TRACE, uDebugFlag,                       __VA_ARGS__); }}
146
0
#define uDebugL(...){ if (uDebugFlag & DEBUG_DEBUG) { taosPrintLongString("UTL DEBUG ", DEBUG_DEBUG, uDebugFlag,                      __VA_ARGS__); }}
147
#define uInfoL(...) { if (uDebugFlag & DEBUG_INFO)  { taosPrintLongString("UTL INFO  ", DEBUG_INFO,  tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
148
149
#define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
150
#define pPrint(...) { taosPrintLog("APP INFO  ", DEBUG_INFO, 255, __VA_ARGS__); }
151
// clang-format on
152
153
// #define BUF_PAGE_DEBUG
154
#ifdef __cplusplus
155
}
156
#endif
157
158
#endif /*_TD_UTIL_LOG_H_*/