diff options
-rw-r--r-- | log.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -59,19 +59,31 @@ static const char *print_priority_colour(int priority) { return print_ansi_colour(colour, is_bg, is_bright); } +static const char *priority_to_str(int priority) { + switch (priority) { + case LOG_ERR : return "ERROR"; + case LOG_WARNING: return "WARNING"; + case LOG_NOTICE : return "NOTICE"; + case LOG_INFO : return "INFO"; + case LOG_DEBUG : return "DEBUG"; + default : return "UNKNOWN"; + } +} + void vprintlog(log_output output_type, int priority, const char *fmt, va_list args) { + const char *priority_str = priority_to_str(priority); char *buf = calloc(vformat_len_copy(fmt, args)+1, sizeof(char)); vsprintf(buf, fmt, args); switch (output_type) { case LOG_OUT_SYSLOG: { - syslog(priority, "%s", buf); + syslog(priority, "%s: %s", priority_str, buf); break; } case LOG_OUT_STDERR: case LOG_OUT_STDOUT: { FILE *output = (output_type == LOG_OUT_STDOUT) ? stdout : stderr; - fprintf(output, "%s%s\x1B[0m\n", print_priority_colour(priority), buf); + fprintf(output, "%s%s: %s\x1B[0m\n", print_priority_colour(priority), priority_str, buf); break; } default: |