From fb95a84e6f6eaebf91338e1c7bafc64d1f5a1a2c Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Sun, 25 Mar 2018 15:51:41 -0300 Subject: [PATCH] Linux: Minor log fix (#1092) Use colored log messages only on the terminal. --- drivers/Linux/log.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/Linux/log.c b/drivers/Linux/log.c index e7bd81782..a88bb2df0 100644 --- a/drivers/Linux/log.c +++ b/drivers/Linux/log.c @@ -134,29 +134,24 @@ void vlog(int level, const char *fmt, va_list args) time_t t = time(NULL); struct tm *lt = localtime(&t); - char buf[16]; - buf[strftime(buf, sizeof(buf), "%b %d %H:%M:%S", lt)] = '\0'; + char date[16]; + date[strftime(date, sizeof(date), "%b %d %H:%M:%S", lt)] = '\0'; -#ifdef LOG_DISABLE_COLOR - (void)_log_level_colors; - if (!_log_quiet) { - fprintf(stderr, "%s %-5s ", buf, _log_level_names[level]); - vfprintf(stderr, fmt, args); - } if (_log_file_fp != NULL) { - vfprintf(_log_file_fp, "%s %-5s ", buf, _log_level_names[level]); + fprintf(_log_file_fp, "%s %-5s ", date, _log_level_names[level]); vfprintf(_log_file_fp, fmt, args); } -#else + if (!_log_quiet) { - fprintf(stderr, "%s %s%-5s\x1b[0m ", buf, _log_level_colors[level], _log_level_names[level]); +#ifdef LOG_DISABLE_COLOR + (void)_log_level_colors; + fprintf(stderr, "%s %-5s ", date, _log_level_names[level]); + vfprintf(stderr, fmt, args); +#else + fprintf(stderr, "%s %s%-5s\x1b[0m ", date, _log_level_colors[level], _log_level_names[level]); vfprintf(stderr, fmt, args); - } - if (_log_file_fp != NULL) { - fprintf(_log_file_fp, "%s %s%-5s\x1b[0m ", buf, _log_level_colors[level], _log_level_names[level]); - vfprintf(_log_file_fp, fmt, args); - } #endif + } } if (_log_syslog) {