-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.h
67 lines (58 loc) · 1.49 KB
/
log.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
61
62
63
64
65
66
67
#include <stdio.h>
#define LOG_TURN_ON
#ifdef LOG_TURN_ON
#define log_info(...) do {\
LOG_isEnabled()&&\
printf("<%s %s> %s %s:%d INFO:",__DATE__, __TIME__,__FUNCTION__,__FILE__,__LINE__)&&\
printf(__VA_ARGS__)&&\
printf("\n");\
}while(0)
//__DATE__, __TIME__,__FUNCTION__,__FILE__,__LINE__ 日期宏,时间宏,函数宏,文件宏,行宏
//__VA_ARGS__ 动态参数宏
#define log_warn(...) do {\
LOG_isEnabled()&&\
printf("<%s %s> %s %s:%d WARN:",__DATE__, __TIME__,__FUNCTION__,__FILE__,__LINE__)&&\
printf(__VA_ARGS__)&&\
printf("\n");\
}while(0)
#define log_error(...) do {\
LOG_isEnabled()&&\
printf("<%s %s> %s %s:%d ERROR:",__DATE__, __TIME__,__FUNCTION__,__FILE__,__LINE__)&&\
printf(__VA_ARGS__)&&\
printf("\n");\
}while(0)
#define log_debug(...) do {\
LOG_isEnabled()&&\
printf("<%s %s> %s %s:%d DEBUG:",__DATE__, __TIME__,__FUNCTION__,__FILE__,__LINE__)&&\
printf(__VA_ARGS__)&&\
printf("\n");\
}while(0)
#define log_test(format, ...) do {\
printf(format, __VA_ARGS__);\
printf("\n");\
}while(0)
#else
#define log_info(...)
#define log_warn(...)
#define log_error(...)
#define log_debug(...)
#define log_test(format, ...)
#endif
int logSwitch = 0; //初始化为关闭状态
bool LOG_isEnabled()
{
return logSwitch;
}
int main()
{
logSwitch = 1; //打开日志开关
int a = 10;
int b = 20;
char c = 'c';
char d = 'd';
log_info("a =%d b=%d c=%c d=%c", a,b ,c,d);
log_warn("I'm log_warn ");
log_error("I'm log_error ");
log_debug("I'm log_debug ");
return 1;
}