0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #ifndef _NGX_LOG_H_INCLUDED_
|
|
8 #define _NGX_LOG_H_INCLUDED_
|
|
9
|
|
10
|
|
11 #include <ngx_config.h>
|
|
12 #include <ngx_core.h>
|
|
13
|
|
14
|
|
15 #define NGX_LOG_STDERR 0
|
|
16 #define NGX_LOG_EMERG 1
|
|
17 #define NGX_LOG_ALERT 2
|
|
18 #define NGX_LOG_CRIT 3
|
|
19 #define NGX_LOG_ERR 4
|
|
20 #define NGX_LOG_WARN 5
|
|
21 #define NGX_LOG_NOTICE 6
|
|
22 #define NGX_LOG_INFO 7
|
|
23 #define NGX_LOG_DEBUG 8
|
|
24
|
|
25 #define NGX_LOG_DEBUG_CORE 0x010
|
|
26 #define NGX_LOG_DEBUG_ALLOC 0x020
|
|
27 #define NGX_LOG_DEBUG_MUTEX 0x040
|
|
28 #define NGX_LOG_DEBUG_EVENT 0x080
|
|
29 #define NGX_LOG_DEBUG_HTTP 0x100
|
290
|
30 #define NGX_LOG_DEBUG_MAIL 0x200
|
194
|
31 #define NGX_LOG_DEBUG_MYSQL 0x400
|
0
|
32
|
|
33 /*
|
|
34 * do not forget to update debug_levels[] in src/core/ngx_log.c
|
|
35 * after the adding a new debug level
|
|
36 */
|
|
37
|
|
38 #define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG_CORE
|
290
|
39 #define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_MYSQL
|
0
|
40 #define NGX_LOG_DEBUG_CONNECTION 0x80000000
|
|
41 #define NGX_LOG_DEBUG_ALL 0x7ffffff0
|
|
42
|
|
43
|
32
|
44 typedef u_char *(*ngx_log_handler_pt) (ngx_log_t *log, u_char *buf, size_t len);
|
0
|
45
|
|
46
|
|
47 struct ngx_log_s {
|
|
48 ngx_uint_t log_level;
|
|
49 ngx_open_file_t *file;
|
32
|
50
|
44
|
51 ngx_atomic_uint_t connection;
|
32
|
52
|
|
53 ngx_log_handler_pt handler;
|
0
|
54 void *data;
|
32
|
55
|
|
56 /*
|
|
57 * we declare "action" as "char *" because the actions are usually
|
|
58 * the static strings and in the "u_char *" case we have to override
|
|
59 * their types all the time
|
|
60 */
|
|
61
|
|
62 char *action;
|
0
|
63 };
|
|
64
|
10
|
65
|
|
66 #define NGX_MAX_ERROR_STR 2048
|
0
|
67
|
|
68
|
|
69 /*********************************/
|
|
70
|
584
|
71 #if (NGX_HAVE_C99_VARIADIC_MACROS)
|
|
72
|
|
73 #define NGX_HAVE_VARIADIC_MACROS 1
|
|
74
|
|
75 #define ngx_log_error(level, log, ...) \
|
|
76 if ((log)->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__)
|
|
77
|
|
78 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
|
79 const char *fmt, ...);
|
|
80
|
|
81 #define ngx_log_debug(level, log, ...) \
|
|
82 if ((log)->log_level & level) \
|
|
83 ngx_log_error_core(NGX_LOG_DEBUG, log, __VA_ARGS__)
|
|
84
|
|
85 /*********************************/
|
|
86
|
|
87 #elif (NGX_HAVE_GCC_VARIADIC_MACROS)
|
0
|
88
|
4
|
89 #define NGX_HAVE_VARIADIC_MACROS 1
|
0
|
90
|
32
|
91 #define ngx_log_error(level, log, args...) \
|
92
|
92 if ((log)->log_level >= level) ngx_log_error_core(level, log, args)
|
0
|
93
|
|
94 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
48
|
95 const char *fmt, ...);
|
0
|
96
|
32
|
97 #define ngx_log_debug(level, log, args...) \
|
92
|
98 if ((log)->log_level & level) \
|
32
|
99 ngx_log_error_core(NGX_LOG_DEBUG, log, args)
|
|
100
|
0
|
101 /*********************************/
|
|
102
|
|
103 #else /* NO VARIADIC MACROS */
|
|
104
|
4
|
105 #define NGX_HAVE_VARIADIC_MACROS 0
|
0
|
106
|
52
|
107 void ngx_cdecl ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
48
|
108 const char *fmt, ...);
|
0
|
109 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
48
|
110 const char *fmt, va_list args);
|
52
|
111 void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
|
|
112 const char *fmt, ...);
|
0
|
113
|
|
114
|
|
115 #endif /* VARIADIC MACROS */
|
|
116
|
|
117
|
|
118 /*********************************/
|
|
119
|
|
120 #if (NGX_DEBUG)
|
|
121
|
4
|
122 #if (NGX_HAVE_VARIADIC_MACROS)
|
0
|
123
|
658
|
124 #define ngx_log_debug0(level, log, err, fmt) \
|
|
125 ngx_log_debug(level, log, err, fmt)
|
|
126
|
|
127 #define ngx_log_debug1(level, log, err, fmt, arg1) \
|
|
128 ngx_log_debug(level, log, err, fmt, arg1)
|
|
129
|
|
130 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \
|
|
131 ngx_log_debug(level, log, err, fmt, arg1, arg2)
|
|
132
|
|
133 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) \
|
|
134 ngx_log_debug(level, log, err, fmt, arg1, arg2, arg3)
|
|
135
|
|
136 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) \
|
|
137 ngx_log_debug(level, log, err, fmt, arg1, arg2, arg3, arg4)
|
|
138
|
|
139 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) \
|
|
140 ngx_log_debug(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
|
|
141
|
|
142 #define ngx_log_debug6(level, log, err, fmt, \
|
|
143 arg1, arg2, arg3, arg4, arg5, arg6) \
|
|
144 ngx_log_debug(level, log, err, fmt, \
|
|
145 arg1, arg2, arg3, arg4, arg5, arg6)
|
|
146
|
|
147 #define ngx_log_debug7(level, log, err, fmt, \
|
|
148 arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
|
|
149 ngx_log_debug(level, log, err, fmt, \
|
|
150 arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
|
151
|
|
152 #define ngx_log_debug8(level, log, err, fmt, \
|
|
153 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
|
|
154 ngx_log_debug(level, log, err, fmt, \
|
|
155 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
|
0
|
156
|
64
|
157
|
0
|
158 #else /* NO VARIADIC MACROS */
|
|
159
|
32
|
160 #define ngx_log_debug0(level, log, err, fmt) \
|
92
|
161 if ((log)->log_level & level) \
|
0
|
162 ngx_log_debug_core(log, err, fmt)
|
|
163
|
32
|
164 #define ngx_log_debug1(level, log, err, fmt, arg1) \
|
92
|
165 if ((log)->log_level & level) \
|
0
|
166 ngx_log_debug_core(log, err, fmt, arg1)
|
|
167
|
32
|
168 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \
|
92
|
169 if ((log)->log_level & level) \
|
0
|
170 ngx_log_debug_core(log, err, fmt, arg1, arg2)
|
|
171
|
32
|
172 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) \
|
92
|
173 if ((log)->log_level & level) \
|
0
|
174 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3)
|
|
175
|
32
|
176 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) \
|
92
|
177 if ((log)->log_level & level) \
|
0
|
178 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4)
|
|
179
|
32
|
180 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) \
|
92
|
181 if ((log)->log_level & level) \
|
0
|
182 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5)
|
|
183
|
32
|
184 #define ngx_log_debug6(level, log, err, fmt, \
|
|
185 arg1, arg2, arg3, arg4, arg5, arg6) \
|
92
|
186 if ((log)->log_level & level) \
|
0
|
187 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
|
|
188
|
32
|
189 #define ngx_log_debug7(level, log, err, fmt, \
|
|
190 arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
|
92
|
191 if ((log)->log_level & level) \
|
32
|
192 ngx_log_debug_core(log, err, fmt, \
|
0
|
193 arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
|
194
|
32
|
195 #define ngx_log_debug8(level, log, err, fmt, \
|
|
196 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
|
92
|
197 if ((log)->log_level & level) \
|
32
|
198 ngx_log_debug_core(log, err, fmt, \
|
|
199 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
|
|
200
|
0
|
201 #endif
|
|
202
|
|
203 #else /* NO NGX_DEBUG */
|
|
204
|
|
205 #define ngx_log_debug0(level, log, err, fmt)
|
|
206 #define ngx_log_debug1(level, log, err, fmt, arg1)
|
|
207 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
|
|
208 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)
|
|
209 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)
|
|
210 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
|
|
211 #define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
|
|
212 #define ngx_log_debug7(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, \
|
|
213 arg6, arg7)
|
32
|
214 #define ngx_log_debug8(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, \
|
|
215 arg6, arg7, arg8)
|
0
|
216
|
|
217 #endif
|
|
218
|
|
219 /*********************************/
|
|
220
|
482
|
221 ngx_log_t *ngx_log_init(u_char *prefix);
|
484
|
222 ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name);
|
|
223 char *ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log);
|
482
|
224 void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
|
|
225 void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
|
484
|
226 u_char *ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err);
|
0
|
227
|
|
228
|
648
|
229 /*
|
|
230 * ngx_write_stderr() cannot be implemented as macro, since
|
|
231 * MSVC does not allow to use #ifdef inside macro parameters.
|
|
232 *
|
|
233 * ngx_write_fd() is used instead of ngx_write_console(), since
|
|
234 * CharToOemBuff() inside ngx_write_console() cannot be used with
|
|
235 * read only buffer as destination and CharToOemBuff() is not needed
|
|
236 * for ngx_write_stderr() anyway.
|
|
237 */
|
|
238 static ngx_inline void
|
|
239 ngx_write_stderr(char *text)
|
|
240 {
|
|
241 (void) ngx_write_fd(ngx_stderr, text, strlen(text));
|
|
242 }
|
|
243
|
|
244
|
0
|
245 extern ngx_module_t ngx_errlog_module;
|
482
|
246 extern ngx_uint_t ngx_use_stderr;
|
0
|
247
|
|
248
|
|
249 #endif /* _NGX_LOG_H_INCLUDED_ */
|