3 * Copyright (C) Igor Sysoev
7 #ifndef _NGX_LOG_H_INCLUDED_
8 #define _NGX_LOG_H_INCLUDED_
11 #include <ngx_config.h>
15 #define NGX_LOG_STDERR 0
16 #define NGX_LOG_EMERG 1
17 #define NGX_LOG_ALERT 2
18 #define NGX_LOG_CRIT 3
20 #define NGX_LOG_WARN 5
21 #define NGX_LOG_NOTICE 6
22 #define NGX_LOG_INFO 7
23 #define NGX_LOG_DEBUG 8
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_MAIL 0x200
31 #define NGX_LOG_DEBUG_MYSQL 0x400
34 * do not forget to update debug_levels[] in src/core/ngx_log.c
35 * after the adding a new debug level
38 #define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG_CORE
39 #define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_MYSQL
40 #define NGX_LOG_DEBUG_CONNECTION 0x80000000
41 #define NGX_LOG_DEBUG_ALL 0x7ffffff0
44 typedef u_char *(*ngx_log_handler_pt) (ngx_log_t *log, u_char *buf, size_t len);
49 ngx_open_file_t *file;
51 ngx_atomic_uint_t connection;
53 ngx_log_handler_pt handler;
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
66 #define NGX_MAX_ERROR_STR 2048
69 /*********************************/
71 #if (NGX_HAVE_GCC_VARIADIC_MACROS)
73 #define NGX_HAVE_VARIADIC_MACROS 1
75 #define ngx_log_error(level, log, args...) \
76 if ((log)->log_level >= level) ngx_log_error_core(level, log, args)
78 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
79 const char *fmt, ...);
81 #define ngx_log_debug(level, log, args...) \
82 if ((log)->log_level & level) \
83 ngx_log_error_core(NGX_LOG_DEBUG, log, args)
85 /*********************************/
87 #elif (NGX_HAVE_C99_VARIADIC_MACROS)
89 #define NGX_HAVE_VARIADIC_MACROS 1
91 #define ngx_log_error(level, log, ...) \
92 if ((log)->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__)
94 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
95 const char *fmt, ...);
97 #define ngx_log_debug(level, log, ...) \
98 if ((log)->log_level & level) \
99 ngx_log_error_core(NGX_LOG_DEBUG, log, __VA_ARGS__)
101 /*********************************/
103 #else /* NO VARIADIC MACROS */
105 #define NGX_HAVE_VARIADIC_MACROS 0
107 void ngx_cdecl ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
108 const char *fmt, ...);
109 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
110 const char *fmt, va_list args);
111 void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
112 const char *fmt, ...);
115 #endif /* VARIADIC MACROS */
118 /*********************************/
122 #if (NGX_HAVE_VARIADIC_MACROS)
124 #define ngx_log_debug0 ngx_log_debug
125 #define ngx_log_debug1 ngx_log_debug
126 #define ngx_log_debug2 ngx_log_debug
127 #define ngx_log_debug3 ngx_log_debug
128 #define ngx_log_debug4 ngx_log_debug
129 #define ngx_log_debug5 ngx_log_debug
130 #define ngx_log_debug6 ngx_log_debug
131 #define ngx_log_debug7 ngx_log_debug
132 #define ngx_log_debug8 ngx_log_debug
135 #else /* NO VARIADIC MACROS */
137 #define ngx_log_debug0(level, log, err, fmt) \
138 if ((log)->log_level & level) \
139 ngx_log_debug_core(log, err, fmt)
141 #define ngx_log_debug1(level, log, err, fmt, arg1) \
142 if ((log)->log_level & level) \
143 ngx_log_debug_core(log, err, fmt, arg1)
145 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \
146 if ((log)->log_level & level) \
147 ngx_log_debug_core(log, err, fmt, arg1, arg2)
149 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) \
150 if ((log)->log_level & level) \
151 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3)
153 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) \
154 if ((log)->log_level & level) \
155 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4)
157 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) \
158 if ((log)->log_level & level) \
159 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5)
161 #define ngx_log_debug6(level, log, err, fmt, \
162 arg1, arg2, arg3, arg4, arg5, arg6) \
163 if ((log)->log_level & level) \
164 ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
166 #define ngx_log_debug7(level, log, err, fmt, \
167 arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
168 if ((log)->log_level & level) \
169 ngx_log_debug_core(log, err, fmt, \
170 arg1, arg2, arg3, arg4, arg5, arg6, arg7)
172 #define ngx_log_debug8(level, log, err, fmt, \
173 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
174 if ((log)->log_level & level) \
175 ngx_log_debug_core(log, err, fmt, \
176 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
180 #else /* NO NGX_DEBUG */
182 #define ngx_log_debug0(level, log, err, fmt)
183 #define ngx_log_debug1(level, log, err, fmt, arg1)
184 #define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
185 #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)
186 #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)
187 #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
188 #define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
189 #define ngx_log_debug7(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, \
191 #define ngx_log_debug8(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, \
196 /*********************************/
198 ngx_log_t *ngx_log_init(void);
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 void ngx_log_abort(ngx_err_t err, const char *text);
204 extern ngx_module_t ngx_errlog_module;
207 #endif /* _NGX_LOG_H_INCLUDED_ */