ulog
This commit is contained in:
parent
6c60dc8e9b
commit
ea43a849b9
|
@ -68,6 +68,18 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, .
|
||||||
#endif
|
#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 pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
||||||
|
#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 _TD_UTIL_ULOG_H
|
|
||||||
#define _TD_UTIL_ULOG_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "tlog.h"
|
|
||||||
|
|
||||||
extern int32_t uDebugFlag;
|
|
||||||
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 pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
|
||||||
#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_UTIL_ULOG_H*/
|
|
|
@ -14,32 +14,30 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "tlog.h"
|
|
||||||
#include "os.h"
|
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "ulog.h"
|
#include "ulog.h"
|
||||||
|
|
||||||
#define LOG_MAX_LINE_SIZE (1000)
|
#define LOG_MAX_LINE_SIZE (1000)
|
||||||
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 10)
|
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 10)
|
||||||
#define LOG_MAX_LINE_CONTENT_SIZE (LOG_MAX_LINE_SIZE - 100)
|
#define LOG_MAX_LINE_CONTENT_SIZE (LOG_MAX_LINE_SIZE - 100)
|
||||||
#define LOG_MAX_LINE_DUMP_SIZE (65 * 1024)
|
#define LOG_MAX_LINE_DUMP_SIZE (65 * 1024)
|
||||||
#define LOG_MAX_LINE_DUMP_BUFFER_SIZE (LOG_MAX_LINE_DUMP_SIZE + 10)
|
#define LOG_MAX_LINE_DUMP_BUFFER_SIZE (LOG_MAX_LINE_DUMP_SIZE + 10)
|
||||||
#define LOG_MAX_LINE_DUMP_CONTENT_SIZE (LOG_MAX_LINE_DUMP_SIZE - 100)
|
#define LOG_MAX_LINE_DUMP_CONTENT_SIZE (LOG_MAX_LINE_DUMP_SIZE - 100)
|
||||||
|
|
||||||
#define LOG_FILE_NAME_LEN 300
|
#define LOG_FILE_NAME_LEN 300
|
||||||
#define TSDB_DEFAULT_LOG_BUF_SIZE (20 * 1024 * 1024) // 20MB
|
#define LOG_DEFAULT_BUF_SIZE (20 * 1024 * 1024) // 20MB
|
||||||
|
|
||||||
#define DEFAULT_LOG_INTERVAL 25
|
#define LOG_DEFAULT_INTERVAL 25
|
||||||
#define LOG_INTERVAL_STEP 5
|
#define LOG_INTERVAL_STEP 5
|
||||||
#define MIN_LOG_INTERVAL 5
|
#define LOG_MIN_INTERVAL 5
|
||||||
#define MAX_LOG_INTERVAL 25
|
#define LOG_MAX_INTERVAL 25
|
||||||
#define LOG_MAX_WAIT_MSEC 1000
|
#define LOG_MAX_WAIT_MSEC 1000
|
||||||
|
|
||||||
#define LOG_BUF_BUFFER(x) ((x)->buffer)
|
#define LOG_BUF_BUFFER(x) ((x)->buffer)
|
||||||
#define LOG_BUF_START(x) ((x)->buffStart)
|
#define LOG_BUF_START(x) ((x)->buffStart)
|
||||||
#define LOG_BUF_END(x) ((x)->buffEnd)
|
#define LOG_BUF_END(x) ((x)->buffEnd)
|
||||||
#define LOG_BUF_SIZE(x) ((x)->buffSize)
|
#define LOG_BUF_SIZE(x) ((x)->buffSize)
|
||||||
#define LOG_BUF_MUTEX(x) ((x)->buffMutex)
|
#define LOG_BUF_MUTEX(x) ((x)->buffMutex)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
@ -72,7 +70,7 @@ int32_t tsLogKeepDays = 0;
|
||||||
bool tsAsyncLog = true;
|
bool tsAsyncLog = true;
|
||||||
bool tsLogInited = false;
|
bool tsLogInited = false;
|
||||||
int64_t asyncLogLostLines = 0;
|
int64_t asyncLogLostLines = 0;
|
||||||
int32_t writeInterval = DEFAULT_LOG_INTERVAL;
|
int32_t writeInterval = LOG_DEFAULT_INTERVAL;
|
||||||
|
|
||||||
// log
|
// log
|
||||||
int32_t tsNumOfLogLines = 10000000;
|
int32_t tsNumOfLogLines = 10000000;
|
||||||
|
@ -123,7 +121,7 @@ int32_t taosInitLog(const char *logName, int maxFiles) {
|
||||||
char fullName[PATH_MAX] = {0};
|
char fullName[PATH_MAX] = {0};
|
||||||
snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logName);
|
snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logName);
|
||||||
|
|
||||||
tsLogObj.logHandle = taosLogBuffNew(TSDB_DEFAULT_LOG_BUF_SIZE);
|
tsLogObj.logHandle = taosLogBuffNew(LOG_DEFAULT_BUF_SIZE);
|
||||||
if (tsLogObj.logHandle == NULL) return -1;
|
if (tsLogObj.logHandle == NULL) return -1;
|
||||||
if (taosOpenLogFile(fullName, tsNumOfLogLines, maxFiles) < 0) return -1;
|
if (taosOpenLogFile(fullName, tsNumOfLogLines, maxFiles) < 0) return -1;
|
||||||
if (taosStartLog() < 0) return -1;
|
if (taosStartLog() < 0) return -1;
|
||||||
|
@ -140,7 +138,7 @@ static void taosStopLog() {
|
||||||
void taosCloseLog() {
|
void taosCloseLog() {
|
||||||
taosStopLog();
|
taosStopLog();
|
||||||
// tsem_post(&(tsLogObj.logHandle->buffNotEmpty));
|
// tsem_post(&(tsLogObj.logHandle->buffNotEmpty));
|
||||||
taosMsleep(MAX_LOG_INTERVAL / 1000);
|
taosMsleep(LOG_MAX_INTERVAL / 1000);
|
||||||
if (taosCheckPthreadValid(tsLogObj.logHandle->asyncThread)) {
|
if (taosCheckPthreadValid(tsLogObj.logHandle->asyncThread)) {
|
||||||
pthread_join(tsLogObj.logHandle->asyncThread, NULL);
|
pthread_join(tsLogObj.logHandle->asyncThread, NULL);
|
||||||
}
|
}
|
||||||
|
@ -629,7 +627,7 @@ static void taosWriteLog(SLogBuff *tLogBuff) {
|
||||||
|
|
||||||
if (start == end) {
|
if (start == end) {
|
||||||
dbgEmptyW++;
|
dbgEmptyW++;
|
||||||
writeInterval = MAX_LOG_INTERVAL;
|
writeInterval = LOG_MAX_INTERVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,14 +656,14 @@ static void taosWriteLog(SLogBuff *tLogBuff) {
|
||||||
|
|
||||||
if (pollSize < tLogBuff->minBuffSize) {
|
if (pollSize < tLogBuff->minBuffSize) {
|
||||||
dbgSmallWN++;
|
dbgSmallWN++;
|
||||||
if (writeInterval < MAX_LOG_INTERVAL) {
|
if (writeInterval < LOG_MAX_INTERVAL) {
|
||||||
writeInterval += LOG_INTERVAL_STEP;
|
writeInterval += LOG_INTERVAL_STEP;
|
||||||
}
|
}
|
||||||
} else if (pollSize > LOG_BUF_SIZE(tLogBuff) / 3) {
|
} else if (pollSize > LOG_BUF_SIZE(tLogBuff) / 3) {
|
||||||
dbgBigWN++;
|
dbgBigWN++;
|
||||||
writeInterval = MIN_LOG_INTERVAL;
|
writeInterval = LOG_MIN_INTERVAL;
|
||||||
} else if (pollSize > LOG_BUF_SIZE(tLogBuff) / 4) {
|
} else if (pollSize > LOG_BUF_SIZE(tLogBuff) / 4) {
|
||||||
if (writeInterval > MIN_LOG_INTERVAL) {
|
if (writeInterval > LOG_MIN_INTERVAL) {
|
||||||
writeInterval -= LOG_INTERVAL_STEP;
|
writeInterval -= LOG_INTERVAL_STEP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -680,7 +678,7 @@ static void taosWriteLog(SLogBuff *tLogBuff) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeInterval = MIN_LOG_INTERVAL;
|
writeInterval = LOG_MIN_INTERVAL;
|
||||||
|
|
||||||
remainChecked = 1;
|
remainChecked = 1;
|
||||||
} while (1);
|
} while (1);
|
||||||
|
@ -707,7 +705,7 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
char *data = malloc(compressSize);
|
char *data = malloc(compressSize);
|
||||||
// gzFile dstFp = NULL;
|
// gzFile dstFp = NULL;
|
||||||
|
|
||||||
// srcFp = fopen(srcFileName, "r");
|
// srcFp = fopen(srcFileName, "r");
|
||||||
TdFilePtr pSrcFile = taosOpenFile(srcFileName, TD_FILE_READ);
|
TdFilePtr pSrcFile = taosOpenFile(srcFileName, TD_FILE_READ);
|
||||||
|
@ -722,25 +720,25 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
||||||
goto cmp_end;
|
goto cmp_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dstFp = gzdopen(fd, "wb6f");
|
// dstFp = gzdopen(fd, "wb6f");
|
||||||
// if (dstFp == NULL) {
|
// if (dstFp == NULL) {
|
||||||
// ret = -3;
|
// ret = -3;
|
||||||
// close(fd);
|
// close(fd);
|
||||||
// goto cmp_end;
|
// goto cmp_end;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// while (!feof(srcFp)) {
|
// while (!feof(srcFp)) {
|
||||||
// len = (int32_t)fread(data, 1, compressSize, srcFp);
|
// len = (int32_t)fread(data, 1, compressSize, srcFp);
|
||||||
// (void)gzwrite(dstFp, data, len);
|
// (void)gzwrite(dstFp, data, len);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
cmp_end:
|
cmp_end:
|
||||||
if (pSrcFile) {
|
if (pSrcFile) {
|
||||||
taosCloseFile(&pSrcFile);
|
taosCloseFile(&pSrcFile);
|
||||||
}
|
}
|
||||||
// if (dstFp) {
|
// if (dstFp) {
|
||||||
// gzclose(dstFp);
|
// gzclose(dstFp);
|
||||||
// }
|
// }
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue