提交 c3a7a957 编写于 作者: S Shengliang Guan

TD-2371

上级 aa3df5f7
...@@ -36,10 +36,11 @@ typedef struct { ...@@ -36,10 +36,11 @@ typedef struct {
extern SNoteObj tsHttpNote; extern SNoteObj tsHttpNote;
extern SNoteObj tsTscNote; extern SNoteObj tsTscNote;
extern SNoteObj tsErrorNote; extern SNoteObj tsInfoNote;
void taosInitNotes(); void taosInitNotes();
void taosNotePrint(SNoteObj* pNote, const char* const format, ...); void taosNotePrint(SNoteObj* pNote, const char* const format, ...);
void taosNotePrintBuffer(SNoteObj *pNote, char *buffer, int32_t len);
#define nPrintHttp(...) \ #define nPrintHttp(...) \
if (tsHttpEnableRecordSql) { \ if (tsHttpEnableRecordSql) { \
...@@ -51,7 +52,7 @@ void taosNotePrint(SNoteObj* pNote, const char* const format, ...); ...@@ -51,7 +52,7 @@ void taosNotePrint(SNoteObj* pNote, const char* const format, ...);
taosNotePrint(&tsTscNote, __VA_ARGS__); \ taosNotePrint(&tsTscNote, __VA_ARGS__); \
} }
#define nError(...) taosNotePrint(&tsErrorNote, __VA_ARGS__); #define nInfo(buffer, len) taosNotePrintBuffer(&tsInfoNote, buffer, len);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "os.h" #include "os.h"
#include "tulog.h" #include "tulog.h"
#include "tlog.h" #include "tlog.h"
#include "tnote.h"
#include "tutil.h" #include "tutil.h"
#define MAX_LOGLINE_SIZE (1000) #define MAX_LOGLINE_SIZE (1000)
...@@ -400,6 +401,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { ...@@ -400,6 +401,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) {
} }
if (dflag & DEBUG_SCREEN) taosWrite(1, buffer, (uint32_t)len); if (dflag & DEBUG_SCREEN) taosWrite(1, buffer, (uint32_t)len);
if (dflag == 255) nInfo(buffer, len);
} }
void taosDumpData(unsigned char *msg, int32_t len) { void taosDumpData(unsigned char *msg, int32_t len) {
......
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
SNoteObj tsHttpNote; SNoteObj tsHttpNote;
SNoteObj tsTscNote; SNoteObj tsTscNote;
SNoteObj tsErrorNote; SNoteObj tsInfoNote;
static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum, SNoteObj * pNote); static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum, SNoteObj *pNote);
static void taosCloseNoteByFd(int32_t oldFd, SNoteObj * pNote); static void taosCloseNoteByFd(int32_t oldFd, SNoteObj *pNote);
void taosInitNote(int32_t numOfLines, int32_t maxNotes, SNoteObj *pNote, char *name) { static void taosInitNote(int32_t numOfLines, int32_t maxNotes, SNoteObj *pNote, char *name) {
memset(pNote, 0, sizeof(SNoteObj)); memset(pNote, 0, sizeof(SNoteObj));
pNote->fileNum = 1; pNote->fileNum = 1;
pNote->fd = -1; pNote->fd = -1;
...@@ -54,12 +54,12 @@ void taosInitNotes() { ...@@ -54,12 +54,12 @@ void taosInitNotes() {
} }
if (tscEmbedded == 1) { if (tscEmbedded == 1) {
snprintf(name, TSDB_FILENAME_LEN * 2, "%s/note", tsLogDir); snprintf(name, TSDB_FILENAME_LEN * 2, "%s/taosinfo", tsLogDir);
taosInitNote(tsNumOfLogLines, 1, &tsErrorNote, name); taosInitNote(tsNumOfLogLines, 1, &tsInfoNote, name);
} }
} }
bool taosLockNote(int32_t fd, SNoteObj *pNote) { static bool taosLockNote(int32_t fd, SNoteObj *pNote) {
if (fd < 0) return false; if (fd < 0) return false;
if (pNote->fileNum > 1) { if (pNote->fileNum > 1) {
...@@ -72,7 +72,7 @@ bool taosLockNote(int32_t fd, SNoteObj *pNote) { ...@@ -72,7 +72,7 @@ bool taosLockNote(int32_t fd, SNoteObj *pNote) {
return false; return false;
} }
void taosUnLockNote(int32_t fd, SNoteObj *pNote) { static void taosUnLockNote(int32_t fd, SNoteObj *pNote) {
if (fd < 0) return; if (fd < 0) return;
if (pNote->fileNum > 1) { if (pNote->fileNum > 1) {
...@@ -80,7 +80,7 @@ void taosUnLockNote(int32_t fd, SNoteObj *pNote) { ...@@ -80,7 +80,7 @@ void taosUnLockNote(int32_t fd, SNoteObj *pNote) {
} }
} }
void *taosThreadToOpenNewNote(void *param) { static void *taosThreadToOpenNewNote(void *param) {
char name[NOTE_FILE_NAME_LEN * 2]; char name[NOTE_FILE_NAME_LEN * 2];
SNoteObj *pNote = (SNoteObj *)param; SNoteObj *pNote = (SNoteObj *)param;
...@@ -108,7 +108,7 @@ void *taosThreadToOpenNewNote(void *param) { ...@@ -108,7 +108,7 @@ void *taosThreadToOpenNewNote(void *param) {
return NULL; return NULL;
} }
int32_t taosOpenNewNote(SNoteObj *pNote) { static int32_t taosOpenNewNote(SNoteObj *pNote) {
pthread_mutex_lock(&pNote->mutex); pthread_mutex_lock(&pNote->mutex);
if (pNote->lines > pNote->maxLines && pNote->openInProgress == 0) { if (pNote->lines > pNote->maxLines && pNote->openInProgress == 0) {
...@@ -129,7 +129,7 @@ int32_t taosOpenNewNote(SNoteObj *pNote) { ...@@ -129,7 +129,7 @@ int32_t taosOpenNewNote(SNoteObj *pNote) {
return pNote->fd; return pNote->fd;
} }
bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) { static bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) {
int32_t fd = open(noteName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); int32_t fd = open(noteName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "failed to open note:%s reason:%s\n", noteName, strerror(errno)); fprintf(stderr, "failed to open note:%s reason:%s\n", noteName, strerror(errno));
...@@ -146,7 +146,7 @@ bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) { ...@@ -146,7 +146,7 @@ bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) {
} }
} }
void taosGetNoteName(char *fn, SNoteObj *pNote) { static void taosGetNoteName(char *fn, SNoteObj *pNote) {
if (pNote->fileNum > 1) { if (pNote->fileNum > 1) {
for (int32_t i = 0; i < pNote->fileNum; i++) { for (int32_t i = 0; i < pNote->fileNum; i++) {
char fileName[NOTE_FILE_NAME_LEN]; char fileName[NOTE_FILE_NAME_LEN];
...@@ -169,7 +169,7 @@ void taosGetNoteName(char *fn, SNoteObj *pNote) { ...@@ -169,7 +169,7 @@ void taosGetNoteName(char *fn, SNoteObj *pNote) {
} }
} }
int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum, SNoteObj *pNote) { static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum, SNoteObj *pNote) {
char name[NOTE_FILE_NAME_LEN * 2] = {0}; char name[NOTE_FILE_NAME_LEN * 2] = {0};
int32_t size; int32_t size;
struct stat logstat0, logstat1; struct stat logstat0, logstat1;
...@@ -227,6 +227,16 @@ int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum, ...@@ -227,6 +227,16 @@ int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum,
return 0; return 0;
} }
void taosNotePrintBuffer(SNoteObj *pNote, char *buffer, int32_t len) {
if (pNote->fd < 0) return;
taosWrite(pNote->fd, buffer, len);
if (pNote->maxLines > 0) {
pNote->lines++;
if ((pNote->lines > pNote->maxLines) && (pNote->openInProgress == 0)) taosOpenNewNote(pNote);
}
}
void taosNotePrint(SNoteObj *pNote, const char *const format, ...) { void taosNotePrint(SNoteObj *pNote, const char *const format, ...) {
va_list argpointer; va_list argpointer;
char buffer[MAX_NOTE_LINE_SIZE + 2]; char buffer[MAX_NOTE_LINE_SIZE + 2];
...@@ -249,19 +259,12 @@ void taosNotePrint(SNoteObj *pNote, const char *const format, ...) { ...@@ -249,19 +259,12 @@ void taosNotePrint(SNoteObj *pNote, const char *const format, ...) {
buffer[len++] = '\n'; buffer[len++] = '\n';
buffer[len] = 0; buffer[len] = 0;
if (pNote->fd >= 0) { taosNotePrintBuffer(pNote, buffer, len);
taosWrite(pNote->fd, buffer, len);
if (pNote->maxLines > 0) {
pNote->lines++;
if ((pNote->lines > pNote->maxLines) && (pNote->openInProgress == 0)) taosOpenNewNote(pNote);
}
}
} }
void taosCloseNote(SNoteObj *pNote) { taosCloseNoteByFd(pNote->fd, pNote); } // static void taosCloseNote(SNoteObj *pNote) { taosCloseNoteByFd(pNote->fd, pNote); }
void taosCloseNoteByFd(int32_t fd, SNoteObj *pNote) { static void taosCloseNoteByFd(int32_t fd, SNoteObj *pNote) {
if (fd >= 0) { if (fd >= 0) {
taosUnLockNote(fd, pNote); taosUnLockNote(fd, pNote);
close(fd); close(fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册