Update tlog
This commit is contained in:
21
src/tlog.c
21
src/tlog.c
@@ -315,7 +315,7 @@ static int _tlog_format(char *buff, int maxlen, struct tlog_info *info, void *us
|
|||||||
tlog_get_level_string(info->level), info->file, info->line);
|
tlog_get_level_string(info->level), info->file, info->line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len < 0 || len == maxlen) {
|
if (len < 0 || len >= maxlen) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
buff += len;
|
buff += len;
|
||||||
@@ -353,28 +353,31 @@ static int _tlog_root_log_buffer(char *buff, int maxlen, void *userptr, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
max_format_len = maxlen - len - 2;
|
max_format_len = maxlen - len - 2;
|
||||||
|
buff[maxlen - 1] = 0;
|
||||||
log_len = tlog_format(buff + len, max_format_len, &info_inter->info, info_inter->userptr, format, ap);
|
log_len = tlog_format(buff + len, max_format_len, &info_inter->info, info_inter->userptr, format, ap);
|
||||||
if (log_len < 0) {
|
if (log_len < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (log_len >= max_format_len) {
|
} else if (log_len >= max_format_len) {
|
||||||
buff[max_format_len - 1] = '.';
|
buff[len + max_format_len - 2] = '.';
|
||||||
buff[max_format_len - 2] = '.';
|
buff[len + max_format_len - 3] = '.';
|
||||||
buff[max_format_len - 3] = '.';
|
buff[len + max_format_len - 4] = '.';
|
||||||
log_len = max_format_len;
|
log_len = max_format_len - 1;
|
||||||
}
|
}
|
||||||
len += log_len;
|
len += log_len;
|
||||||
|
|
||||||
/* add new line character*/
|
/* add new line character*/
|
||||||
if (*(buff + len - 1) != '\n' && len + 1 < maxlen - len) {
|
if (*(buff + len - 1) != '\n' && len + 1 < maxlen - 1) {
|
||||||
*(buff + len) = '\n';
|
*(buff + len) = '\n';
|
||||||
len++;
|
len++;
|
||||||
log_len++;
|
log_len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tlog.root->segment_log && len + 1 < maxlen - len) {
|
if (tlog.root->segment_log) {
|
||||||
|
if (len + 1 < maxlen - 1) {
|
||||||
*(buff + len) = '\0';
|
*(buff + len) = '\0';
|
||||||
len++;
|
len++;
|
||||||
log_len++;
|
log_len++;
|
||||||
|
}
|
||||||
log_head->len = log_len;
|
log_head->len = log_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1299,6 +1302,10 @@ static int _tlog_root_write_log(struct tlog_log *log, char *buff, int bufflen)
|
|||||||
struct tlog_segment_log_head *head = NULL;
|
struct tlog_segment_log_head *head = NULL;
|
||||||
static struct tlog_segment_log_head empty_info;
|
static struct tlog_segment_log_head empty_info;
|
||||||
if (tlog.output_func == NULL) {
|
if (tlog.output_func == NULL) {
|
||||||
|
if (log->segment_log) {
|
||||||
|
head = (struct tlog_segment_log_head *)buff;
|
||||||
|
return _tlog_write(log, head->data, head->len);
|
||||||
|
}
|
||||||
return _tlog_write(log, buff, bufflen);
|
return _tlog_write(log, buff, bufflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/tlog.h
14
src/tlog.h
@@ -24,13 +24,13 @@ typedef enum {
|
|||||||
|
|
||||||
struct tlog_time {
|
struct tlog_time {
|
||||||
int year;
|
int year;
|
||||||
int mon;
|
unsigned char mon;
|
||||||
int mday;
|
unsigned char mday;
|
||||||
int hour;
|
unsigned char hour;
|
||||||
int min;
|
unsigned char min;
|
||||||
int sec;
|
unsigned char sec;
|
||||||
int usec;
|
unsigned char usec;
|
||||||
};
|
} __attribute__((packed));
|
||||||
|
|
||||||
#ifndef TLOG_MAX_LINE_LEN
|
#ifndef TLOG_MAX_LINE_LEN
|
||||||
#define TLOG_MAX_LINE_LEN (1024)
|
#define TLOG_MAX_LINE_LEN (1024)
|
||||||
|
|||||||
Reference in New Issue
Block a user