summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-08-04 12:14:25 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-08-04 12:14:25 -0300
commit9660b8af7a810812cb71a7d513532484efd0dd36 (patch)
tree94195ef615dc19061a826edc9d02c4af5d3f9b86
parent7d4f5aec3eca63ace47e01c8ef09b0dec95b876c (diff)
log: Add priority name to log output
-rw-r--r--log.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/log.c b/log.c
index e1e71fc..e0c77e5 100644
--- a/log.c
+++ b/log.c
@@ -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: