1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "log.h"
static const char *log_levels[] = {
"info",
"warning",
"error",
"fatal",
};
void log_msg(enum log_level level, const char *namespace, const char *format, ...) {
va_list args;
va_start(args, format);
fprintf(stderr, "%s: %s: ", log_levels[level], namespace);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
if (level == LOG_ERROR) {
exit(EXIT_FAILURE);
} else if (level == LOG_FATAL) {
abort();
}
va_end(args);
}
|