-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog.h
More file actions
73 lines (58 loc) · 1.85 KB
/
log.h
File metadata and controls
73 lines (58 loc) · 1.85 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
#ifndef APP_PUBLIC_LOGGER_H_
#define APP_PUBLIC_LOGGER_H_
#include<stdio.h>
extern FILE *logger_fd;
#define __DEBUG //日志模块总开关,注释掉将关闭日志输出
#ifdef __DEBUG
#define DEBUG(format, ...) \
do { \
if (logger_fd != NULL) \
fprintf(logger_fd, format, ##__VA_ARGS__);\
else \
printf (format, ##__VA_ARGS__); \
}while(0)
#else
#define DEBUG(format, ...)
#endif
//定义日志级别
enum LOG_LEVEL {
LOG_LEVEL_OFF=0,
LOG_LEVEL_FATAL,
LOG_LEVEL_ERR,
LOG_LEVEL_WARN,
LOG_LEVEL_INFO,
LOG_LEVEL_ALL
};
void log_init();
void log_close();
#define log_fatal(level,format, ...) \
do { \
if(level>=LOG_LEVEL_FATAL)\
DEBUG("fatal %s:%d(%s) %s-%s " format "\n",\
__FILE__, __LINE__,__func__, __DATE__,__TIME__, ##__VA_ARGS__ );\
} while (0)
#define log_err(level,format, ...) \
do { \
if(level>=LOG_LEVEL_ERR)\
DEBUG("error %s:%d(%s) %s-%s " format "\n",\
__FILE__, __LINE__,__func__, __DATE__,__TIME__, ##__VA_ARGS__ );\
} while (0)
#define log_warn(level,format, ...) \
do { \
if(level>=LOG_LEVEL_WARN)\
DEBUG("warning %s:%d(%s) %s-%s " format "\n",\
__FILE__, __LINE__,__func__, __DATE__,__TIME__, ##__VA_ARGS__ );\
} while (0)
#define log_info(level,format, ...) \
do { \
if(level>=LOG_LEVEL_INFO)\
DEBUG("info %s:%d(%s) %s-%s " format "\n",\
__FILE__, __LINE__,__func__, __DATE__,__TIME__, ##__VA_ARGS__ );\
} while (0)
#define log_debug(level,format, ...) \
do { \
if(level>=LOG_LEVEL_ALL)\
DEBUG("\n %s:%d(%s) %s-%s " format "\n",\
__FILE__, __LINE__,__func__, __DATE__,__TIME__, ##__VA_ARGS__ );\
} while (0)
#endif /* APP_PUBLIC_LOGGER_H_ */