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
|
|
30 #define NGX_LOG_DEBUG_IMAP 0x200
|
|
31
|
|
32 /*
|
|
33 * do not forget to update debug_levels[] in src/core/ngx_log.c
|
|
34 * after the adding a new debug level
|
|
35 */
|
|
36
|
|
37 #define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG_CORE
|
|
38 #define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_IMAP
|
|
39 #define NGX_LOG_DEBUG_CONNECTION 0x80000000
|
|
40 #define NGX_LOG_DEBUG_ALL 0x7ffffff0
|
|
41
|
|
42
|
32
|
43 typedef u_char *(*ngx_log_handler_pt) (ngx_log_t *log, u_char *buf, size_t len);
|
0
|
44
|
|
45
|
|
46 struct ngx_log_s {
|
|
47 ngx_uint_t log_level;
|
|
48 ngx_open_file_t *file;
|
32
|
49
|
|
50 ngx_uint_t connection;
|
|
51
|
|
52 ngx_log_handler_pt handler;
|
0
|
53 void *data;
|
32
|
54
|
|
55 /*
|
|
56 * we declare "action" as "char *" because the actions are usually
|
|
57 * the static strings and in the "u_char *" case we have to override
|
|
58 * their types all the time
|
|
59 */
|
|
60
|
|
61 char *action;
|
0
|
62 };
|
|
63
|
10
|
64
|
|
65 #define NGX_MAX_ERROR_STR 2048
|
0
|
66
|
|
67
|
|
68 /*********************************/
|
|
69
|
4
|
70 #if (NGX_HAVE_GCC_VARIADIC_MACROS)
|
0
|
71
|
4
|
72 #define NGX_HAVE_VARIADIC_MACROS 1
|
0
|
73
|
32
|
74 #define ngx_log_error(level, log, args...) \
|
0
|
75 if (log->log_level >= level) ngx_log_error_core(level, log, args)
|
|
76
|
|
77 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
|
78 const char *fmt, ...);
|
|
79
|
32
|
80 #define ngx_log_debug(level, log, args...) \
|
|
81 if (log->log_level & level) \
|
|
82 ngx_log_error_core(NGX_LOG_DEBUG, log, args)
|
|
83
|
0
|
84 /*********************************/
|
|
85
|
4
|
86 #elif (NGX_HAVE_C99_VARIADIC_MACROS)
|
0
|
87
|
4
|
88 #define NGX_HAVE_VARIADIC_MACROS 1
|
0
|
89
|
32
|
90 #define ngx_log_error(level, log, ...) \
|
0
|
91 if (log->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__)
|
|
92
|
|
93 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
|
94 const char *fmt, ...);
|
|
95
|
32
|
96 #define ngx_log_debug(level, log, ...) \
|
|
97 if (log->log_level & level) \
|
|
98 ngx_log_error_core(NGX_LOG_DEBUG, log, __VA_ARGS__)
|
|
99
|
0
|
100 /*********************************/
|
|
101
|
|
102 #else /* NO VARIADIC MACROS */
|
|
103
|
4
|
104 #define NGX_HAVE_VARIADIC_MACROS 0
|
0
|
105
|
|
106 void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
|
107 const char *fmt, ...);
|
|
108 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
|
109 const char *fmt, va_list args);
|
|
110 void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...);
|
|
111
|
|
112
|
|
113 #endif /* VARIADIC MACROS */
|
|
114
|
|
115
|
|
116 /*********************************/
|
|
117
|
|
118 #if (NGX_DEBUG)
|
|
119
|
4
|
120 #if (NGX_HAVE_VARIADIC_MACROS)
|
0
|
121
|
32
|
122 #define ngx_log_debug0 ngx_log_debug
|
|
123 #define ngx_log_debug1 ngx_log_debug
|
|
124 #define ngx_log_debug2 ngx_log_debug
|
|
125 #define ngx_log_debug3 ngx_log_debug
|
|
126 #define ngx_log_debug4 ngx_log_debug
|
|
127 #define ngx_log_debug5 ngx_log_debug
|
|
128 #define ngx_log_debug6 ngx_log_debug
|
|
129 #define ngx_log_debug7 ngx_log_debug
|
|
130 #define ngx_log_debug8 ngx_log_debug
|
0
|
131
|
|
132 #else /* NO VARIADIC MACROS */
|
|
133
|
32
|
134 #define ngx_log_debug0(level, log, err, fmt) \
|
|
135 if (log->log_level & level) \
|
0
|
136 ngx_log_debug_core(log, err, fmt)
|
|
137
|
32
|
138 #define ngx_log_debug1(level, log, err, fmt, arg1) \
|
|
139 if (log->log_level & level) \
|
0
|
140 ngx_log_debug_core(log, err, fmt, arg1)
|
|
141
|
32
|
142 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \
|
|
143 if (log->log_level & level) \
|
0
|
144 ngx_log_debug_core(log, err, fmt, arg1, arg2)
|
|
145
|
32
|
146 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) \
|
|
147 if (log->log_level & level) \
|
0
|
148 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3)
|
|
149
|
32
|
150 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) \
|
|
151 if (log->log_level & level) \
|
0
|
152 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4)
|
|
153
|
32
|
154 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) \
|
|
155 if (log->log_level & level) \
|
0
|
156 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5)
|
|
157
|
32
|
158 #define ngx_log_debug6(level, log, err, fmt, \
|
|
159 arg1, arg2, arg3, arg4, arg5, arg6) \
|
|
160 if (log->log_level & level) \
|
0
|
161 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
|
|
162
|
32
|
163 #define ngx_log_debug7(level, log, err, fmt, \
|
|
164 arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
|
|
165 if (log->log_level & level) \
|
|
166 ngx_log_debug_core(log, err, fmt, \
|
0
|
167 arg1, arg2, arg3, arg4, arg5, arg6, arg7)
|
|
168
|
32
|
169 #define ngx_log_debug8(level, log, err, fmt, \
|
|
170 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
|
|
171 if (log->log_level & level) \
|
|
172 ngx_log_debug_core(log, err, fmt, \
|
|
173 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
|
|
174
|
0
|
175 #endif
|
|
176
|
|
177 #else /* NO NGX_DEBUG */
|
|
178
|
|
179 #define ngx_log_debug0(level, log, err, fmt)
|
|
180 #define ngx_log_debug1(level, log, err, fmt, arg1)
|
|
181 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
|
|
182 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)
|
|
183 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)
|
|
184 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
|
|
185 #define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
|
|
186 #define ngx_log_debug7(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, \
|
|
187 arg6, arg7)
|
32
|
188 #define ngx_log_debug8(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, \
|
|
189 arg6, arg7, arg8)
|
0
|
190
|
|
191 #endif
|
|
192
|
|
193 /*********************************/
|
|
194
|
|
195 #define ngx_log_alloc_log(pool, log) ngx_palloc(pool, log, sizeof(ngx_log_t))
|
|
196 #define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t))
|
|
197
|
10
|
198 ngx_log_t *ngx_log_init();
|
0
|
199 ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args);
|
|
200 char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);
|
|
201
|
|
202
|
|
203
|
|
204 extern ngx_module_t ngx_errlog_module;
|
|
205
|
|
206
|
|
207 #endif /* _NGX_LOG_H_INCLUDED_ */
|