-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlog.c
46 lines (40 loc) · 936 Bytes
/
log.c
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
#include "log.h"
#include <stdio.h>
#include <stdarg.h>
static enum loglevel loglevel = LV_ERROR;
static const char *loglevelstr[] = {
"dbg",
"inf",
"ERR",
};
void log_set_loglevel(enum loglevel loglevel_) {
loglevel = loglevel_;
}
void log_line(enum loglevel loglevel_, const char *fmt, ...) {
if (loglevel_ < loglevel)
return;
va_list args;
va_start(args, fmt);
fprintf(stderr, "[wlanthy:%s] ", loglevelstr[loglevel_]);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
}
void log_head(enum loglevel loglevel_) {
if (loglevel_ < loglevel)
return;
fprintf(stderr, "[wlanthy:%s] ", loglevelstr[loglevel_]);
}
void log_body(enum loglevel loglevel_, const char *fmt, ...) {
if (loglevel_ < loglevel)
return;
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
void log_tail(enum loglevel loglevel_) {
if (loglevel_ < loglevel)
return;
fprintf(stderr, "\n");
}