refact log
This commit is contained in:
parent
d414167214
commit
17b71c1d0c
|
@ -100,7 +100,7 @@ int64_t dbgBigWN = 0;
|
||||||
int64_t dbgWSize = 0;
|
int64_t dbgWSize = 0;
|
||||||
|
|
||||||
static void *taosAsyncOutputLog(void *param);
|
static void *taosAsyncOutputLog(void *param);
|
||||||
static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen);
|
static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t msgLen);
|
||||||
static SLogBuff *taosLogBuffNew(int32_t bufSize);
|
static SLogBuff *taosLogBuffNew(int32_t bufSize);
|
||||||
static void taosCloseLogByFd(TdFilePtr pFile);
|
static void taosCloseLogByFd(TdFilePtr pFile);
|
||||||
static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum);
|
static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum);
|
||||||
|
@ -395,33 +395,19 @@ static void taosUpdateLogNums(ELogLevel level) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) {
|
static inline int32_t taosBuildLogHead(char *buffer, const char *flags) {
|
||||||
if (!osLogSpaceAvailable()) return;
|
|
||||||
|
|
||||||
va_list argpointer;
|
|
||||||
char buffer[LOG_MAX_LINE_BUFFER_SIZE];
|
|
||||||
int32_t len;
|
|
||||||
struct tm Tm, *ptm;
|
struct tm Tm, *ptm;
|
||||||
struct timeval timeSecs;
|
struct timeval timeSecs;
|
||||||
time_t curTime;
|
|
||||||
|
|
||||||
taosGetTimeOfDay(&timeSecs);
|
taosGetTimeOfDay(&timeSecs);
|
||||||
curTime = timeSecs.tv_sec;
|
time_t curTime = timeSecs.tv_sec;
|
||||||
ptm = localtime_r(&curTime, &Tm);
|
ptm = localtime_r(&curTime, &Tm);
|
||||||
|
|
||||||
len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
|
return sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " %s", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
|
||||||
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId());
|
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(), flags);
|
||||||
len += sprintf(buffer + len, "%s", flags);
|
}
|
||||||
|
|
||||||
va_start(argpointer, format);
|
|
||||||
len += vsnprintf(buffer + len, LOG_MAX_LINE_BUFFER_SIZE - len, format, argpointer);
|
|
||||||
va_end(argpointer);
|
|
||||||
|
|
||||||
if (len > LOG_MAX_LINE_SIZE) len = LOG_MAX_LINE_SIZE;
|
|
||||||
|
|
||||||
buffer[len++] = '\n';
|
|
||||||
buffer[len] = 0;
|
|
||||||
|
|
||||||
|
static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *buffer, int32_t len) {
|
||||||
if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->pFile != NULL) {
|
if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->pFile != NULL) {
|
||||||
taosUpdateLogNums(level);
|
taosUpdateLogNums(level);
|
||||||
if (tsAsyncLog) {
|
if (tsAsyncLog) {
|
||||||
|
@ -432,8 +418,9 @@ void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char
|
||||||
|
|
||||||
if (tsLogObj.maxLines > 0) {
|
if (tsLogObj.maxLines > 0) {
|
||||||
atomic_add_fetch_32(&tsLogObj.lines, 1);
|
atomic_add_fetch_32(&tsLogObj.lines, 1);
|
||||||
|
if ((tsLogObj.lines > tsLogObj.maxLines) && (tsLogObj.openInProgress == 0)) {
|
||||||
if ((tsLogObj.lines > tsLogObj.maxLines) && (tsLogObj.openInProgress == 0)) taosOpenNewLogFile();
|
taosOpenNewLogFile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,6 +429,42 @@ void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) {
|
||||||
|
if (!osLogSpaceAvailable()) return;
|
||||||
|
|
||||||
|
char buffer[LOG_MAX_LINE_BUFFER_SIZE];
|
||||||
|
int32_t len = taosBuildLogHead(buffer, flags);
|
||||||
|
|
||||||
|
va_list argpointer;
|
||||||
|
va_start(argpointer, format);
|
||||||
|
len += vsnprintf(buffer + len, LOG_MAX_LINE_BUFFER_SIZE - len, format, argpointer);
|
||||||
|
va_end(argpointer);
|
||||||
|
|
||||||
|
if (len > LOG_MAX_LINE_SIZE) len = LOG_MAX_LINE_SIZE;
|
||||||
|
buffer[len++] = '\n';
|
||||||
|
buffer[len] = 0;
|
||||||
|
|
||||||
|
taosPrintLogImp(level, dflag, buffer, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) {
|
||||||
|
if (!osLogSpaceAvailable()) return;
|
||||||
|
|
||||||
|
char buffer[LOG_MAX_LINE_DUMP_BUFFER_SIZE];
|
||||||
|
int32_t len = taosBuildLogHead(buffer, flags);
|
||||||
|
|
||||||
|
va_list argpointer;
|
||||||
|
va_start(argpointer, format);
|
||||||
|
len += vsnprintf(buffer + len, LOG_MAX_LINE_DUMP_BUFFER_SIZE - len, format, argpointer);
|
||||||
|
va_end(argpointer);
|
||||||
|
|
||||||
|
if (len > LOG_MAX_LINE_DUMP_SIZE) len = LOG_MAX_LINE_DUMP_SIZE;
|
||||||
|
buffer[len++] = '\n';
|
||||||
|
buffer[len] = 0;
|
||||||
|
|
||||||
|
taosPrintLogImp(level, dflag, buffer, len);
|
||||||
|
}
|
||||||
|
|
||||||
void taosDumpData(unsigned char *msg, int32_t len) {
|
void taosDumpData(unsigned char *msg, int32_t len) {
|
||||||
if (!osLogSpaceAvailable()) return;
|
if (!osLogSpaceAvailable()) return;
|
||||||
taosUpdateLogNums(DEBUG_DUMP);
|
taosUpdateLogNums(DEBUG_DUMP);
|
||||||
|
@ -466,53 +489,6 @@ void taosDumpData(unsigned char *msg, int32_t len) {
|
||||||
taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos);
|
taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...) {
|
|
||||||
if (!osLogSpaceAvailable()) return;
|
|
||||||
|
|
||||||
va_list argpointer;
|
|
||||||
char buffer[LOG_MAX_LINE_DUMP_BUFFER_SIZE];
|
|
||||||
int32_t len;
|
|
||||||
struct tm Tm, *ptm;
|
|
||||||
struct timeval timeSecs;
|
|
||||||
time_t curTime;
|
|
||||||
|
|
||||||
taosGetTimeOfDay(&timeSecs);
|
|
||||||
curTime = timeSecs.tv_sec;
|
|
||||||
ptm = localtime_r(&curTime, &Tm);
|
|
||||||
|
|
||||||
len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
|
|
||||||
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId());
|
|
||||||
len += sprintf(buffer + len, "%s", flags);
|
|
||||||
|
|
||||||
va_start(argpointer, format);
|
|
||||||
len += vsnprintf(buffer + len, LOG_MAX_LINE_DUMP_BUFFER_SIZE, format, argpointer);
|
|
||||||
va_end(argpointer);
|
|
||||||
|
|
||||||
if (len > LOG_MAX_LINE_DUMP_SIZE) len = LOG_MAX_LINE_DUMP_SIZE;
|
|
||||||
|
|
||||||
buffer[len++] = '\n';
|
|
||||||
buffer[len] = 0;
|
|
||||||
|
|
||||||
if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->pFile != NULL) {
|
|
||||||
taosUpdateLogNums(level);
|
|
||||||
if (tsAsyncLog) {
|
|
||||||
taosPushLogBuffer(tsLogObj.logHandle, buffer, len);
|
|
||||||
} else {
|
|
||||||
taosWriteFile(tsLogObj.logHandle->pFile, buffer, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsLogObj.maxLines > 0) {
|
|
||||||
atomic_add_fetch_32(&tsLogObj.lines, 1);
|
|
||||||
|
|
||||||
if ((tsLogObj.lines > tsLogObj.maxLines) && (tsLogObj.openInProgress == 0)) taosOpenNewLogFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dflag & DEBUG_SCREEN) {
|
|
||||||
write(1, buffer, (uint32_t)len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void taosCloseLogByFd(TdFilePtr pFile) {
|
static void taosCloseLogByFd(TdFilePtr pFile) {
|
||||||
if (pFile != NULL) {
|
if (pFile != NULL) {
|
||||||
taosUnLockLogFile(pFile);
|
taosUnLockLogFile(pFile);
|
||||||
|
@ -545,7 +521,7 @@ _err:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosCopyLogBuffer(SLogBuff *tLogBuff, int32_t start, int32_t end, char *msg, int32_t msgLen) {
|
static void taosCopyLogBuffer(SLogBuff *tLogBuff, int32_t start, int32_t end, const char *msg, int32_t msgLen) {
|
||||||
if (start > end) {
|
if (start > end) {
|
||||||
memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, msgLen);
|
memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, msgLen);
|
||||||
} else {
|
} else {
|
||||||
|
@ -559,7 +535,7 @@ static void taosCopyLogBuffer(SLogBuff *tLogBuff, int32_t start, int32_t end, ch
|
||||||
LOG_BUF_END(tLogBuff) = (LOG_BUF_END(tLogBuff) + msgLen) % LOG_BUF_SIZE(tLogBuff);
|
LOG_BUF_END(tLogBuff) = (LOG_BUF_END(tLogBuff) + msgLen) % LOG_BUF_SIZE(tLogBuff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen) {
|
static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t msgLen) {
|
||||||
int32_t start = 0;
|
int32_t start = 0;
|
||||||
int32_t end = 0;
|
int32_t end = 0;
|
||||||
int32_t remainSize = 0;
|
int32_t remainSize = 0;
|
||||||
|
|
Loading…
Reference in New Issue