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
43
44
45
46
47
48
49
50
51
52
|
/*
* Created by yuuta on 1/1/22.
*/
#include "log.h"
#include "config.h"
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
void g_log(enum log_level level,
const char *file,
int line,
const char *format,
...) {
if (config == NULL || config->out == NULL) {
return;
}
FILE *stream = config->out;
switch (level) {
case log_fetal:
fprintf(stream, "F");
break;
case log_error:
fprintf(stream, "E");
break;
case log_warn:
fprintf(stream, "W");
break;
case log_info:
fprintf(stream, "I");
break;
case log_debug:
#ifdef DEBUG
fprintf(stream, "D");
break;
#else
return;
#endif
default:
fprintf(stderr, "Unknown log level: %d.\n", level);
assert(0);
}
fprintf(stream, "[%s:%d]: ",
file, line);
va_list list;
va_start(list, format);
vfprintf(stream, format, list);
va_end(list);
fprintf(stream, "\n");
}
|