1 #include <string.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4 
5 #include <libconflate/conflate.h>
6 #include "conflate_internal.h"
7 
lvl_name(enum conflate_log_level lvl)8 static char* lvl_name(enum conflate_log_level lvl)
9 {
10     char *rv = NULL;
11 
12     switch(lvl) {
13     case LOG_LVL_FATAL: rv = "FATAL"; break;
14     case LOG_LVL_ERROR: rv = "ERROR"; break;
15     case LOG_LVL_WARN: rv = "WARN"; break;
16     case LOG_LVL_INFO: rv = "INFO"; break;
17     case LOG_LVL_DEBUG: rv = "DEBUG"; break;
18     }
19 
20     return rv;
21 }
22 
conflate_stderr_logger(void *userdata, enum conflate_log_level lvl, const char *msg, ...)23 void conflate_stderr_logger(void *userdata, enum conflate_log_level lvl,
24                             const char *msg, ...)
25 {
26     char fmt[512];
27     va_list ap;
28 
29     snprintf(fmt, sizeof(fmt), "%s: %s\n", lvl_name(lvl), msg);
30     va_start(ap, msg);
31     vfprintf(stderr, fmt, ap);
32     va_end(ap);
33     (void)userdata;
34 }
35