-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.h
83 lines (65 loc) · 1.93 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef LOG_H
#define LOG_H
#include <stdarg.h>
#include <pthread.h>
typedef enum {
LOG_FATAL,
LOG_ERROR,
LOG_INFO,
LOG_DEBUG,
LOG_DEBUG1,
LOG_DEBUG2,
LOG_NOLEVEL
}LOG_LEVEL;
enum {
LOG_STDOUT,
LOG_FILE
};
typedef struct log_arg {
int log_level;
int log_file_num;
int log_size;
char log_path[1024];
char curr_log[1024];
FILE *log_fp;
pthread_mutex_t log_lock;
}LOG_ARG;
void log_lock(void);
void log_unlock(void);
#define debug(fmt, ...) do_log(LOG_DEBUG, LOG_FILE, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define __debug(fmt, ...) do_log(LOG_DEBUG, LOG_STDOUT, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define debug1(fmt, ...) do_log(LOG_DEBUG1, LOG_FILE, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define __debug1(fmt, ...) do_log(LOG_DEBUG1, LOG_STDOUT, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define debug2(fmt, ...) do_log(LOG_DEBUG2, LOG_FILE, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define __debug2(fmt, ...) do_log(LOG_DEBUG2, LOG_STDOUT, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define fatal(fmt, ...) do_log(LOG_FATAL, LOG_FILE, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define __fatal(fmt, ...) do_log(LOG_FATAL, LOG_STDOUT, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define error(fmt, ...) do_log(LOG_ERROR, LOG_FILE, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define __error(fmt, ...) do_log(LOG_ERROR, LOG_STDOUT, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define info(fmt, ...) do_log(LOG_INFO, LOG_FILE, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#define __info(fmt, ...) do_log(LOG_INFO, LOG_STDOUT, __FILE__, \
__FUNCTION__, __LINE__, \
fmt, ##__VA_ARGS__);
#endif