upstream nginx-0.7.31
[nginx.git] / nginx / src / core / ngx_log.h
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_MAIL        0x200
31 #define NGX_LOG_DEBUG_MYSQL       0x400
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
39 #define NGX_LOG_DEBUG_LAST        NGX_LOG_DEBUG_MYSQL
40 #define NGX_LOG_DEBUG_CONNECTION  0x80000000
41 #define NGX_LOG_DEBUG_ALL         0x7ffffff0
42
43
44 typedef u_char *(*ngx_log_handler_pt) (ngx_log_t *log, u_char *buf, size_t len);
45
46
47 struct ngx_log_s {
48     ngx_uint_t           log_level;
49     ngx_open_file_t     *file;
50
51     ngx_atomic_uint_t    connection;
52
53     ngx_log_handler_pt   handler;
54     void                *data;
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;
63 };
64
65
66 #define NGX_MAX_ERROR_STR   2048
67
68
69 /*********************************/
70
71 #if (NGX_HAVE_GCC_VARIADIC_MACROS)
72
73 #define NGX_HAVE_VARIADIC_MACROS  1
74
75 #define ngx_log_error(level, log, args...)                                    \
76     if ((log)->log_level >= level) ngx_log_error_core(level, log, 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, args...)                                    \
82     if ((log)->log_level & level)                                             \
83         ngx_log_error_core(NGX_LOG_DEBUG, log, args)
84
85 /*********************************/
86
87 #elif (NGX_HAVE_C99_VARIADIC_MACROS)
88
89 #define NGX_HAVE_VARIADIC_MACROS  1
90
91 #define ngx_log_error(level, log, ...)                                        \
92     if ((log)->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__)
93
94 void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
95     const char *fmt, ...);
96
97 #define ngx_log_debug(level, log, ...)                                        \
98     if ((log)->log_level & level)                                             \
99         ngx_log_error_core(NGX_LOG_DEBUG, log, __VA_ARGS__)
100
101 /*********************************/
102
103 #else /* NO VARIADIC MACROS */
104
105 #define NGX_HAVE_VARIADIC_MACROS  0
106
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, ...);
113
114
115 #endif /* VARIADIC MACROS */
116
117
118 /*********************************/
119
120 #if (NGX_DEBUG)
121
122 #if (NGX_HAVE_VARIADIC_MACROS)
123
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
133
134
135 #else /* NO VARIADIC MACROS */
136
137 #define ngx_log_debug0(level, log, err, fmt)                                  \
138     if ((log)->log_level & level)                                             \
139         ngx_log_debug_core(log, err, fmt)
140
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)
144
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)
148
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)
152
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)
156
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)
160
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)
165
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)
171
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)
177
178 #endif
179
180 #else /* NO NGX_DEBUG */
181
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,    \
190                        arg6, arg7)
191 #define ngx_log_debug8(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5,    \
192                        arg6, arg7, arg8)
193
194 #endif
195
196 /*********************************/
197
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);
202
203
204 extern ngx_module_t  ngx_errlog_module;
205
206
207 #endif /* _NGX_LOG_H_INCLUDED_ */