tlog.h 3.7 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

S
Shengliang Guan 已提交
16 17
#ifndef _TD_UTIL_LOG_H_
#define _TD_UTIL_LOG_H_
H
refact  
Hongze Cheng 已提交
18

L
Liu Jicong 已提交
19 20
#include "os.h"

H
refact  
Hongze Cheng 已提交
21 22 23 24
#ifdef __cplusplus
extern "C" {
#endif

25 26 27 28 29 30 31 32 33 34 35
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;
S
Shengliang Guan 已提交
36

S
Shengliang Guan 已提交
37 38
typedef void (*LogFp)(int64_t ts, ELogLevel level, const char *content);

S
Shengliang Guan 已提交
39
extern bool    tsLogEmbedded;
S
Shengliang Guan 已提交
40
extern bool    tsAsyncLog;
S
Shengliang Guan 已提交
41
extern bool    tsAssert;
S
Shengliang Guan 已提交
42 43
extern int32_t tsNumOfLogLines;
extern int32_t tsLogKeepDays;
S
Shengliang Guan 已提交
44
extern LogFp   tsLogFp;
S
Shengliang Guan 已提交
45 46 47 48
extern int64_t tsNumOfErrorLogs;
extern int64_t tsNumOfInfoLogs;
extern int64_t tsNumOfDebugLogs;
extern int64_t tsNumOfTraceLogs;
S
Shengliang Guan 已提交
49 50 51 52 53 54 55 56 57 58 59 60
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;
extern int32_t wDebugFlag;
extern int32_t sDebugFlag;
extern int32_t tsdbDebugFlag;
L
Liu Jicong 已提交
61
extern int32_t tqDebugFlag;
S
Shengliang Guan 已提交
62
extern int32_t fsDebugFlag;
H
Hongze Cheng 已提交
63
extern int32_t metaDebugFlag;
S
Shengliang Guan 已提交
64
extern int32_t udfDebugFlag;
65
extern int32_t smaDebugFlag;
dengyihao's avatar
dengyihao 已提交
66
extern int32_t idxDebugFlag;
M
Minglei Jin 已提交
67
extern int32_t tdbDebugFlag;
D
dapan1121 已提交
68

S
Shengliang Guan 已提交
69
int32_t taosInitLog(const char *logName, int32_t maxFiles);
H
refact  
Hongze Cheng 已提交
70 71
void    taosCloseLog();
void    taosResetLog();
S
Shengliang Guan 已提交
72
void    taosDumpData(uint8_t *msg, int32_t len);
H
refact  
Hongze Cheng 已提交
73

74
void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...)
H
refact  
Hongze Cheng 已提交
75
#ifdef __GNUC__
76
    __attribute__((format(printf, 4, 5)))
H
refact  
Hongze Cheng 已提交
77 78 79
#endif
    ;

80
void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...)
H
refact  
Hongze Cheng 已提交
81
#ifdef __GNUC__
82
    __attribute__((format(printf, 4, 5)))
H
refact  
Hongze Cheng 已提交
83 84 85
#endif
    ;

S
Shengliang Guan 已提交
86 87 88 89
bool taosAssertLog(bool condition, const char *file, int32_t line, const char *format, ...);
#define ASSERTS(condition, ...) taosAssertLog(condition, __FILE__, __LINE__, __VA_ARGS__)
#define ASSERT(condition)       ASSERTS(condition, "assert info not provided")

H
Hongze Cheng 已提交
90
// clang-format off
91 92 93 94 95 96
#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__); }}
97
#define uDebugL(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLongString("UTL ", DEBUG_DEBUG, uDebugFlag, __VA_ARGS__); }}
S
ulog  
Shengliang Guan 已提交
98

99 100
#define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
#define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); }
H
Hongze Cheng 已提交
101
// clang-format on
L
Liu Jicong 已提交
102
//#define BUF_PAGE_DEBUG
H
refact  
Hongze Cheng 已提交
103 104 105 106
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
107
#endif /*_TD_UTIL_LOG_H_*/