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