blob: ec416d6f87b8b57616795d850ada7a4f0368d3ee (
plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include <stdio.h>
#include <stdarg.h>
#include "logging.h"
int global_log_level;
const char *level_string(int level)
{
switch(level) {
case FATAL:
return "FATAL";
case ERROR:
return "ERROR";
case WARN:
return "WARN";
case INFO:
return "INFO";
case DEBUG:
return "DEBUG";
case TRACE:
return "TRACE";
default:
if (level > TRACE)
return "TRACE";
return "[BAD LOG LEVEL]";
}
}
void log_msg(int level, const char *format_string, ...)
{
if (global_log_level >= level) {
va_list args;
va_start(args, format_string);
fprintf(stderr, "[%s] ", level_string(level));
vfprintf(stderr, format_string, args);
fprintf(stderr, "\n");
va_end(args);
}
}
|