-
Notifications
You must be signed in to change notification settings - Fork 0
/
gao_log.h
executable file
·170 lines (135 loc) · 5.36 KB
/
gao_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* log.h
*
* Created on: Oct 13, 2012
* Author: cverge
*/
#ifndef GAO_LOG_H_
#define GAO_LOG_H_
#ifdef __KERNEL__
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#else
#include <string.h>
#include <errno.h>
#include <stdio.h>
#endif
#define LOG_LEVEL_DP 0x0012
#define LOG_LEVEL_DEBUG 0x0010
#define LOG_LEVEL_INFO 0x0008
#define LOG_LEVEL_WARN 0x0006
#define LOG_LEVEL_BUG 0x0005
#define LOG_LEVEL_ERROR 0x0004
#define LOG_LEVEL_FATAL 0x0002
#define LOG_LEVEL_OFF 0x0000
#define GAO_LOG_LEVEL LOG_LEVEL_INFO
#define GAO_LOG_LOCK_ENABLE 0
#define GAO_OUTPUT_FILE stderr
#ifdef __KERNEL__
#if GAO_LOG_LEVEL >= LOG_LEVEL_DEBUG
#define log_dp(FMT, ...) printk("[DATAPLANE:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_dp(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_DEBUG
#define log_debug(FMT, ...) printk("[DEBUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_debug(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_INFO
#define log_info(FMT, ...) printk("[INFO:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_info(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_WARN
#define log_warn(FMT, ...) printk("[WARN:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_warn(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_BUG
#define log_bug(FMT, ...) printk("[BUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_warn(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_ERROR
#define log_error(FMT, ...) printk("[ERROR:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_error(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_FATAL
#define log_fatal(FMT, ...) printk("[FATAL:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_fatal(FMT, ...)
#endif
#if GAO_LOG_LOCK_ENABLE > 0
#define log_lock(FMT, ...) printk("[LOCK:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_lock(FMT, ...)
#endif
#define check_ptr(PTR) if(PTR == NULL) { log_error("malloc Failed!"); goto err; }
#define check_ptr_val(VAL, PTR) if(PTR == NULL) { ret = VAL; log_error("malloc Failed!"); goto err; }
#ifdef GAO_USERSPACE
#define free_null(PTR) { free(PTR); PTR = NULL; }
#else
#define kfree_null(PTR) { kfree(PTR); PTR = NULL; }
#endif
#define gao_error(FMT, ...) { printk("[ERROR:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); goto err; }
#define gao_error_val(VAL, FMT, ...) { ret = VAL; printk("[ERROR:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); goto err; }
#define gao_bug(FMT, ...) { printk("[BUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); goto err; }
#define gao_bug_val(VAL, FMT, ...) { ret = VAL; printk("[BUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); goto err; }
#else
#if GAO_LOG_LEVEL >= LOG_LEVEL_DEBUG
#define log_dp(FMT, ...) fprintf(GAO_OUTPUT_FILE, "[DATAPLANE:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_dp(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_DEBUG
#define log_debug(FMT, ...) fprintf(GAO_OUTPUT_FILE, "[DEBUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_debug(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_INFO
#define log_info(FMT, ...) fprintf(GAO_OUTPUT_FILE, "[INFO:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_info(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_WARN
#define log_warn(FMT, ...) fprintf(GAO_OUTPUT_FILE, "[WARN:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_warn(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_BUG
#define log_bug(FMT, ...) fprintf(GAO_OUTPUT_FILE, "[BUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_error(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_ERROR
#define log_error(FMT, ...) fprintf(GAO_OUTPUT_FILE, "[ERROR:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_error(FMT, ...)
#endif
#if GAO_LOG_LEVEL >= LOG_LEVEL_FATAL
#define log_fatal(FMT, ...) fprintf(GAO_OUTPUT_FILE, "[FATAL:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_fatal(FMT, ...)
#endif
#if GAO_LOG_LOCK_ENABLE > 0
#define log_lock(FMT, ...) fprintf(GAO_OUTPUT_FILE, "[LOCK:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_lock(FMT, ...)
#endif
#define check_ptr(PTR) if(PTR == NULL) { log_error("Malloc Failed!"); goto err; }
#define free_null(PTR) free(PTR); PTR = NULL;
#define gao_error(FMT, ...) { fprintf(GAO_OUTPUT_FILE, "[ERROR:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); goto err; }
#define gao_error_val(VAL, FMT, ...) { ret = VAL; fprintf(GAO_OUTPUT_FILE, "[ERROR:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); goto err; }
#define gao_bug(FMT, ...) { fprintf(GAO_OUTPUT_FILE, "[BUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); goto err; }
#define gao_bug_val(VAL, FMT, ...) { ret = VAL; fprintf(GAO_OUTPUT_FILE, "[BUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); goto err; }
#ifdef __cplusplus
#define gao_error_throw(VAL, FMT, ...) { fprintf(GAO_OUTPUT_FILE, "[ERROR:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); throw (VAL); }
#define gao_bug_throw(VAL, FMT, ...) { fprintf(GAO_OUTPUT_FILE, "[BUG:%s:%d] " FMT "\n", __FILE__, __LINE__, ##__VA_ARGS__); throw (VAL); }
#endif
#endif
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif /* LOG_H_ */