tlog.h 6.8 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * 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/>.
 */

#ifndef TDENGINE_TLOG_H
#define TDENGINE_TLOG_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tglobalcfg.h"

28 29 30 31
#define DEBUG_ERROR 1U
#define DEBUG_WARN  2U
#define DEBUG_TRACE 4U
#define DEBUG_DUMP  8U
H
hzcheng 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

#define DEBUG_FILE   0x80
#define DEBUG_SCREEN 0x40

extern void (*taosLogFp)(int level, const char *const format, ...);

extern void (*taosLogSqlFp)(char *sql);

extern void (*taosLogAcctFp)(char *acctId, int64_t currentPointsPerSecond, int64_t maxPointsPerSecond,
                             int64_t totalTimeSeries, int64_t maxTimeSeries, int64_t totalStorage, int64_t maxStorage,
                             int64_t totalQueryTime, int64_t maxQueryTime, int64_t totalInbound, int64_t maxInbound,
                             int64_t totalOutbound, int64_t maxOutbound, int64_t totalDbs, int64_t maxDbs,
                             int64_t totalUsers, int64_t maxUsers, int64_t totalStreams, int64_t maxStreams,
                             int64_t totalConns, int64_t maxConns, int8_t accessState);

int taosInitLog(char *logName, int numOfLogLines, int maxFiles);

void taosCloseLogger();

void taosDumpData(unsigned char *msg, int len);

int taosOpenLogFile(char *fn);

void tprintf(const char *const flags, int dflag, const char *const format, ...);

void taosPrintLongString(const char *const flags, int dflag, const char *const format, ...);

int taosOpenLogFileWithMaxLines(char *fn, int maxLines, int maxFileNum);

void taosCloseLog();

void taosResetLogFile();

#define taosLogError(...)         \
  if (taosLogFp) {                \
    (*taosLogFp)(2, __VA_ARGS__); \
  }
#define taosLogWarn(...)          \
  if (taosLogFp) {                \
    (*taosLogFp)(1, __VA_ARGS__); \
  }
#define taosLogPrint(...)         \
  if (taosLogFp) {                \
    (*taosLogFp)(0, __VA_ARGS__); \
  }

// utility log function
#define pError(...)                          \
  if (uDebugFlag & DEBUG_ERROR) {            \
    tprintf("ERROR UTL ", 255, __VA_ARGS__); \
  }
#define pWarn(...)                                  \
  if (uDebugFlag & DEBUG_WARN) {                    \
    tprintf("WARN  UTL ", uDebugFlag, __VA_ARGS__); \
  }
#define pTrace(...)                           \
  if (uDebugFlag & DEBUG_TRACE) {             \
    tprintf("UTL ", uDebugFlag, __VA_ARGS__); \
  }
#define pDump(x, y)              \
  if (uDebugFlag & DEBUG_DUMP) { \
    taosDumpData(x, y);          \
  }

#define pPrint(...) \
  { tprintf("UTL ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }

// client log function
100
extern uint32_t cdebugFlag;
H
hzcheng 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

#define tscError(...)                               \
  if (cdebugFlag & DEBUG_ERROR) {                   \
    tprintf("ERROR TSC ", cdebugFlag, __VA_ARGS__); \
  }
#define tscWarn(...)                                \
  if (cdebugFlag & DEBUG_WARN) {                    \
    tprintf("WARN  TSC ", cdebugFlag, __VA_ARGS__); \
  }
#define tscTrace(...)                         \
  if (cdebugFlag & DEBUG_TRACE) {             \
    tprintf("TSC ", cdebugFlag, __VA_ARGS__); \
  }
#define tscPrint(...) \
  { tprintf("TSC ", 255, __VA_ARGS__); }
L
lihui 已提交
116 117 118 119
#define tscDump(...)                                        \
    if (cdebugFlag & DEBUG_TRACE) {                         \
      taosPrintLongString("TSC ", cdebugFlag, __VA_ARGS__); \
    }
H
hzcheng 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
#define jniError(...)                                 \
  if (jnidebugFlag & DEBUG_ERROR) {                   \
    tprintf("ERROR JNI ", jnidebugFlag, __VA_ARGS__); \
  }
#define jniWarn(...)                                  \
  if (jnidebugFlag & DEBUG_WARN) {                    \
    tprintf("WARN  JNI ", jnidebugFlag, __VA_ARGS__); \
  }
#define jniTrace(...)                           \
  if (jnidebugFlag & DEBUG_TRACE) {             \
    tprintf("JNI ", jnidebugFlag, __VA_ARGS__); \
  }
#define jniPrint(...) \
  { tprintf("JNI ", 255, __VA_ARGS__); }

// rpc log function
#define tError(...)                                    \
S
slguan 已提交
137 138
  if (rpcDebugFlag & DEBUG_ERROR) {                   \
    tprintf("ERROR RPC ", rpcDebugFlag, __VA_ARGS__); \
H
hzcheng 已提交
139 140
  }
#define tWarn(...)                                     \
S
slguan 已提交
141 142
  if (rpcDebugFlag & DEBUG_WARN) {                    \
    tprintf("WARN  RPC ", rpcDebugFlag, __VA_ARGS__); \
H
hzcheng 已提交
143 144
  }
#define tTrace(...)                              \
S
slguan 已提交
145 146
  if (rpcDebugFlag & DEBUG_TRACE) {             \
    tprintf("RPC ", rpcDebugFlag, __VA_ARGS__); \
H
hzcheng 已提交
147 148 149 150
  }
#define tPrint(...) \
  { tprintf("RPC ", 255, __VA_ARGS__); }
#define tDump(x, y)                      \
S
slguan 已提交
151
  if (rpcDebugFlag & DEBUG_DUMP) {      \
H
hzcheng 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    taosDumpData((unsigned char *)x, y); \
  }

// dnode log function
#define dError(...)                          \
  if (ddebugFlag & DEBUG_ERROR) {            \
    tprintf("ERROR DND ", 255, __VA_ARGS__); \
  }
#define dWarn(...)                                  \
  if (ddebugFlag & DEBUG_WARN) {                    \
    tprintf("WARN  DND ", ddebugFlag, __VA_ARGS__); \
  }
#define dTrace(...)                           \
  if (ddebugFlag & DEBUG_TRACE) {             \
    tprintf("DND ", ddebugFlag, __VA_ARGS__); \
  }
#define dPrint(...) \
  { tprintf("DND ", 255, __VA_ARGS__); }

#define dLError(...) taosLogError(__VA_ARGS__) dError(__VA_ARGS__)
#define dLWarn(...) taosLogWarn(__VA_ARGS__) dWarn(__VA_ARGS__)
#define dLPrint(...) taosLogPrint(__VA_ARGS__) dPrint(__VA_ARGS__)

#define qTrace(...)                               \
  if (qdebugFlag & DEBUG_TRACE) {                 \
    tprintf("DND QRY ", qdebugFlag, __VA_ARGS__); \
  }

// mnode log function
#define mError(...)                          \
  if (mdebugFlag & DEBUG_ERROR) {            \
    tprintf("ERROR MND ", 255, __VA_ARGS__); \
  }
#define mWarn(...)                                  \
  if (mdebugFlag & DEBUG_WARN) {                    \
    tprintf("WARN  MND ", mdebugFlag, __VA_ARGS__); \
  }
#define mTrace(...)                           \
  if (mdebugFlag & DEBUG_TRACE) {             \
    tprintf("MND ", mdebugFlag, __VA_ARGS__); \
  }
#define mPrint(...) \
  { tprintf("MND ", 255, __VA_ARGS__); }

#define mLError(...) taosLogError(__VA_ARGS__) mError(__VA_ARGS__)
#define mLWarn(...) taosLogWarn(__VA_ARGS__) mWarn(__VA_ARGS__)
#define mLPrint(...) taosLogPrint(__VA_ARGS__) mPrint(__VA_ARGS__)

#ifdef __cplusplus
}
#endif

#endif