]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
log: make show_color variable tristate
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Dec 2020 16:44:36 +0000 (01:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Dec 2020 05:44:02 +0000 (14:44 +0900)
Should not change any behavior.

src/basic/log.c

index 5a87ad3c726cc5f4e93947a3cbe2124937405066..d2aaf08368aa2fd67fee490a7ef8dbc7a9ce1b69 100644 (file)
@@ -51,7 +51,7 @@ static int journal_fd = -1;
 
 static bool syslog_is_stream = false;
 
-static bool show_color = false;
+static int show_color = -1; /* tristate */
 static bool show_location = false;
 static bool show_time = false;
 static bool show_tid = false;
@@ -398,12 +398,12 @@ static int write_to_console(
                 iovec[n++] = IOVEC_MAKE_STRING(tid_string);
         }
 
-        if (show_color)
+        if (log_get_show_color())
                 get_log_colors(LOG_PRI(level), &on, &off, NULL);
 
         if (show_location) {
                 const char *lon = "", *loff = "";
-                if (show_color) {
+                if (log_get_show_color()) {
                         lon = ANSI_HIGHLIGHT_YELLOW4;
                         loff = ANSI_NORMAL;
                 }
@@ -1221,7 +1221,7 @@ void log_show_color(bool b) {
 }
 
 bool log_get_show_color(void) {
-        return show_color;
+        return show_color > 0; /* Defaults to false. */
 }
 
 void log_show_location(bool b) {