aboutsummaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-07-18 08:39:53 +0200
committerDaniel Eklöf <daniel@ekloef.se>2024-07-18 08:39:53 +0200
commitc89bbfe6012275afe500c0c862329f37c4021d73 (patch)
treec08c2fce0d8bd2f5f7004a3343bf7c416ae61b5c /log.c
parentd687493c7cbc3d112db6030ec786b4b719ba075d (diff)
downloadwbg-c89bbfe6012275afe500c0c862329f37c4021d73.tar.gz
log: respect the NO_COLOR environment variable
http://no-color.org/
Diffstat (limited to 'log.c')
-rw-r--r--log.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/log.c b/log.c
index c5d9093..950e641 100644
--- a/log.c
+++ b/log.c
@@ -30,7 +30,13 @@ log_init(enum log_colorize _colorize, bool _do_syslog,
[LOG_CLASS_DEBUG] = LOG_DEBUG,
};
- colorize = _colorize == LOG_COLORIZE_NEVER ? false : _colorize == LOG_COLORIZE_ALWAYS ? true : isatty(STDERR_FILENO);
+ /* Don't use colors if NO_COLOR is defined and not empty */
+ const char *no_color_str = getenv("NO_COLOR");
+ const bool no_color = no_color_str != NULL && no_color_str[0] != '\0';
+
+ colorize = _colorize == LOG_COLORIZE_NEVER
+ ? false : _colorize == LOG_COLORIZE_ALWAYS
+ ? true : !no_color && isatty(STDERR_FILENO);
do_syslog = _do_syslog;
if (do_syslog) {