Skip to content

Commit

Permalink
Linux: Minor log fix (#1092)
Browse files Browse the repository at this point in the history
Use colored log messages only on the terminal.
  • Loading branch information
marceloaqno authored Mar 25, 2018
1 parent ea6d07c commit fb95a84
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions drivers/Linux/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fb95a84

Please sign in to comment.