-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdebug.h
60 lines (51 loc) · 1.51 KB
/
debug.h
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
#ifndef _DSD_DEBUG_H
#define _DSD_DEBUG_H
enum dsd_log_levels {
DSD_ERR = 1 << 0,
DSD_WARN = 1 << 1,
DSD_NOTICE = 1 << 2,
DSD_INFO = 1 << 3,
DSD_DEBUG = 1 << 4,
DSD_COUNT = 6/* set to count of valid flags */
};
/**
* 设置调试级别,表明哪些级别的信息可以打印出来
*/
void dsd_set_log_level(int level);
int dsd_log_filter(int filter);
#define dsdl_notice(format, args...) \
do {\
if (dsd_log_filter(DSD_NOTICE)) {\
fprintf(stderr,"\033[35m" "[%s->%s->%d]-> " "\033[0m",__FILE__,__func__,__LINE__);\
fprintf(stderr,"\033[35m" format "\033[0m", ##args);\
}\
}while(0)
#define dsdl_warn(format, args...) \
do {\
if (dsd_log_filter(DSD_WARN)) {\
fprintf(stderr,"\033[33m" "[%s->%s->%d]-> " "\033[0m",__FILE__,__func__,__LINE__);\
fprintf(stderr,"\033[33m" format "\033[0m", ##args);\
}\
}while(0)
#define dsdl_info(format, args...) \
do {\
if (dsd_log_filter(DSD_INFO)) {\
fprintf(stderr, "\033[32m" "[%s->%s->%d]-> " "\033[0m",__FILE__,__func__,__LINE__);\
fprintf(stderr, "\033[32m" format "\033[0m", ##args);\
}\
}while(0)
#define dsdl_debug(format, args...) \
do {\
if (dsd_log_filter(DSD_DEBUG)) {\
fprintf(stderr, "[%s->%s->%d]-> ",__FILE__,__func__,__LINE__);\
fprintf(stderr, format, ##args);\
}\
}while(0)
#define dsdl_err(format, args...) \
do {\
if (dsd_log_filter(DSD_ERR)) {\
fprintf(stderr,"\033[31m" "[%s->%s->%d]-> " "\033[0m",__FILE__,__func__,__LINE__);\
fprintf(stderr,"\033[31m" format "\033[0m", ##args);\
}\
}while(0)
#endif