Skip to content

Commit 0f1912a

Browse files
committed
tlog: add config for color mode.
1 parent 25a8e61 commit 0f1912a

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/dns_conf/dns_conf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static struct config_item _config_item[] = {
181181
CONF_CUSTOM("log-file", _config_option_parser_filepath, (char *)dns_conf.log_file),
182182
CONF_SIZE("log-size", &dns_conf.log_size, 0, 1024 * 1024 * 1024),
183183
CONF_INT("log-num", &dns_conf.log_num, 0, 1024),
184+
CONF_YESNO("log-color", &dns_conf.log_color_mode),
184185
CONF_YESNO("log-console", &dns_conf.log_console),
185186
CONF_YESNO("log-syslog", &dns_conf.log_syslog),
186187
CONF_INT_BASE("log-file-mode", &dns_conf.log_file_mode, 0, 511, 8),
@@ -360,6 +361,7 @@ static void _dns_conf_default_value_init(void)
360361
dns_conf.log_num = 8;
361362
dns_conf.log_size = 1024 * 128;
362363
dns_conf.log_level = TLOG_ERROR;
364+
dns_conf.log_color_mode = 1;
363365
dns_conf.audit_num = 2;
364366
dns_conf.audit_file_mode = 0640;
365367
dns_conf.audit_size = 1024 * 128;

src/include/smartdns/dns_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ struct dns_config {
701701
char log_file[DNS_MAX_PATH];
702702
size_t log_size;
703703
int log_num;
704+
int log_color_mode;
704705
int log_file_mode;
705706
int log_console;
706707
int log_syslog;

src/smartdns.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static int _smartdns_create_cert(void)
410410
unlink(dns_conf.bind_ca_key_file);
411411
tlog(TLOG_WARN, "regenerate cert with root ca key %s", dns_conf.bind_root_ca_key_file);
412412
}
413-
413+
414414
if (dns_conf_get_ddns_domain()[0] != 0) {
415415
snprintf(ddns_san, sizeof(ddns_san), "DNS:%s", dns_conf_get_ddns_domain());
416416
}
@@ -555,7 +555,14 @@ static int _smartdns_init_log(void)
555555

556556
unsigned int tlog_flag = TLOG_NONBLOCK;
557557
if (enable_log_screen == 1) {
558-
tlog_flag |= TLOG_SCREEN_COLOR;
558+
tlog_flag |= TLOG_SCREEN;
559+
}
560+
561+
if (dns_conf.log_color_mode) {
562+
tlog_flag |= TLOG_SEGMENT;
563+
if (enable_log_screen) {
564+
tlog_flag |= TLOG_SCREEN_COLOR;
565+
}
559566
}
560567

561568
if (dns_conf.log_syslog) {

src/tlog.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ static int _tlog_root_write_screen_log(struct tlog_log *log, struct tlog_loginfo
16441644
static int _tlog_root_write_log(struct tlog_log *log, const char *buff, int bufflen)
16451645
{
16461646
struct tlog_segment_log_head *head = NULL;
1647-
static struct tlog_segment_log_head empty_info;
1647+
static struct tlog_segment_log_head empty_info = { .info.level = TLOG_INFO };
16481648
if (tlog.output_func == NULL) {
16491649
if (log->segment_log) {
16501650
head = (struct tlog_segment_log_head *)buff;
@@ -1662,7 +1662,6 @@ static int _tlog_root_write_log(struct tlog_log *log, const char *buff, int buff
16621662
}
16631663

16641664
_tlog_root_write_screen_log(log, NULL, buff, bufflen);
1665-
memset(&empty_info, 0, sizeof(empty_info));
16661665
return tlog.output_func(&empty_info.info, buff, bufflen, tlog_get_private(log));
16671666
}
16681667

0 commit comments

Comments
 (0)