Jelajahi Sumber

tlog: add config for color mode.

Nick Peng 1 bulan lalu
induk
melakukan
0f1912ab02
4 mengubah file dengan 13 tambahan dan 4 penghapusan
  1. 2 0
      src/dns_conf/dns_conf.c
  2. 1 0
      src/include/smartdns/dns_conf.h
  3. 9 2
      src/smartdns.c
  4. 1 2
      src/tlog.c

+ 2 - 0
src/dns_conf/dns_conf.c

@@ -181,6 +181,7 @@ static struct config_item _config_item[] = {
 	CONF_CUSTOM("log-file", _config_option_parser_filepath, (char *)dns_conf.log_file),
 	CONF_SIZE("log-size", &dns_conf.log_size, 0, 1024 * 1024 * 1024),
 	CONF_INT("log-num", &dns_conf.log_num, 0, 1024),
+	CONF_YESNO("log-color", &dns_conf.log_color_mode),
 	CONF_YESNO("log-console", &dns_conf.log_console),
 	CONF_YESNO("log-syslog", &dns_conf.log_syslog),
 	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)
 	dns_conf.log_num = 8;
 	dns_conf.log_size = 1024 * 128;
 	dns_conf.log_level = TLOG_ERROR;
+	dns_conf.log_color_mode = 1;
 	dns_conf.audit_num = 2;
 	dns_conf.audit_file_mode = 0640;
 	dns_conf.audit_size = 1024 * 128;

+ 1 - 0
src/include/smartdns/dns_conf.h

@@ -701,6 +701,7 @@ struct dns_config {
 	char log_file[DNS_MAX_PATH];
 	size_t log_size;
 	int log_num;
+	int log_color_mode;
 	int log_file_mode;
 	int log_console;
 	int log_syslog;

+ 9 - 2
src/smartdns.c

@@ -410,7 +410,7 @@ static int _smartdns_create_cert(void)
 		unlink(dns_conf.bind_ca_key_file);
 		tlog(TLOG_WARN, "regenerate cert with root ca key %s", dns_conf.bind_root_ca_key_file);
 	}
-	
+
 	if (dns_conf_get_ddns_domain()[0] != 0) {
 		snprintf(ddns_san, sizeof(ddns_san), "DNS:%s", dns_conf_get_ddns_domain());
 	}
@@ -555,7 +555,14 @@ static int _smartdns_init_log(void)
 
 	unsigned int tlog_flag = TLOG_NONBLOCK;
 	if (enable_log_screen == 1) {
-		tlog_flag |= TLOG_SCREEN_COLOR;
+		tlog_flag |= TLOG_SCREEN;
+	}
+
+	if (dns_conf.log_color_mode) {
+		tlog_flag |= TLOG_SEGMENT;
+		if (enable_log_screen) {
+			tlog_flag |= TLOG_SCREEN_COLOR;
+		}
 	}
 
 	if (dns_conf.log_syslog) {

+ 1 - 2
src/tlog.c

@@ -1644,7 +1644,7 @@ static int _tlog_root_write_screen_log(struct tlog_log *log, struct tlog_loginfo
 static int _tlog_root_write_log(struct tlog_log *log, const char *buff, int bufflen)
 {
     struct tlog_segment_log_head *head = NULL;
-    static struct tlog_segment_log_head empty_info;
+    static struct tlog_segment_log_head empty_info = { .info.level = TLOG_INFO };
     if (tlog.output_func == NULL) {
         if (log->segment_log) {
             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
     }
 
     _tlog_root_write_screen_log(log, NULL, buff, bufflen);
-    memset(&empty_info, 0, sizeof(empty_info));
     return tlog.output_func(&empty_info.info, buff, bufflen, tlog_get_private(log));
 }