-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog.c
More file actions
74 lines (65 loc) · 1.67 KB
/
log.c
File metadata and controls
74 lines (65 loc) · 1.67 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "log.h"
static void (*log_error_func)(const char *fmt, va_list args);
static void (*log_warn_func)(const char *fmt, va_list args);
static void (*log_info_func)(const char *fmt, va_list args);
static void (*log_debug_func)(const char *fmt, va_list args);
void proxy_log_set_error_cb(void (*func)(const char *fmt, va_list args)) {
log_error_func = func;
}
void proxy_log_set_warn_cb(void (*func)(const char *fmt, va_list args)) {
log_warn_func = func;
}
void proxy_log_set_info_cb(void (*func)(const char *fmt, va_list args)) {
log_info_func = func;
}
void proxy_log_set_debug_cb(void (*func)(const char *fmt, va_list args)) {
log_debug_func = func;
}
void log_error(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
if (log_error_func) {
log_error_func(fmt, args);
} else {
vprintf(fmt, args);
printf("\n");
}
va_end(args);
}
void log_warn(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
if (log_warn_func) {
log_warn_func(fmt, args);
} else {
vprintf(fmt, args);
printf("\n");
}
va_end(args);
}
void log_info(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
if (log_info_func)
log_info_func(fmt, args);
#ifdef _DEBUG
else {
vprintf(fmt, args);
printf("\n");
}
#endif
va_end(args);
}
void log_debug(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
if (log_debug_func)
log_debug_func(fmt, args);
#ifdef _DEBUG
else {
vprintf(fmt, args);
printf("\n");
}
#endif
va_end(args);
}