Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 1 | #ifndef _NGX_LOG_H_INCLUDED_ |
| 2 | #define _NGX_LOG_H_INCLUDED_ |
| 3 | |
| 4 | |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 5 | #include <ngx_config.h> |
| 6 | #include <ngx_core.h> |
| 7 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 8 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 9 | #define NGX_LOG_STDERR 0 |
| 10 | #define NGX_LOG_EMERG 1 |
| 11 | #define NGX_LOG_ALERT 2 |
| 12 | #define NGX_LOG_CRIT 3 |
| 13 | #define NGX_LOG_ERR 4 |
| 14 | #define NGX_LOG_WARN 5 |
| 15 | #define NGX_LOG_NOTICE 6 |
| 16 | #define NGX_LOG_INFO 7 |
| 17 | #define NGX_LOG_DEBUG 8 |
| 18 | |
Igor Sysoev | 5f80078 | 2003-12-08 20:48:12 +0000 | [diff] [blame] | 19 | #define NGX_LOG_DEBUG_ALLOC 0x10 |
| 20 | #define NGX_LOG_DEBUG_EVENT 0x20 |
| 21 | #define NGX_LOG_DEBUG_HTTP 0x40 |
| 22 | |
| 23 | #define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG |
| 24 | #define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_HTTP |
| 25 | #define NGX_LOG_DEBUG_ALL 0xfffffff8 |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 26 | |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 27 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 28 | /* |
Igor Sysoev | 2b54238 | 2002-08-20 14:48:28 +0000 | [diff] [blame] | 29 | "[%time] [%level] %pid#%tid: %message:(%errno)%errstr, while %action" |
Igor Sysoev | 4e5e117 | 2002-08-22 15:24:03 +0000 | [diff] [blame] | 30 | " %peer and while processing %context" |
Igor Sysoev | 2b54238 | 2002-08-20 14:48:28 +0000 | [diff] [blame] | 31 | |
Igor Sysoev | 4e5e117 | 2002-08-22 15:24:03 +0000 | [diff] [blame] | 32 | ---- |
Igor Sysoev | 2b54238 | 2002-08-20 14:48:28 +0000 | [diff] [blame] | 33 | message = "recv() failed"; |
| 34 | errno = 32; |
| 35 | action = "reading request headers from client"; |
| 36 | peer = "192.168.1.1"; |
| 37 | context = "URL /" |
| 38 | |
Igor Sysoev | 4e5e117 | 2002-08-22 15:24:03 +0000 | [diff] [blame] | 39 | "[2002/08/20 12:00:00] [error] 412#3: recv() failed (32: Broken pipe)" |
Igor Sysoev | 2b54238 | 2002-08-20 14:48:28 +0000 | [diff] [blame] | 40 | " while reading request headers from client 192.168.1.1" |
Igor Sysoev | 4e5e117 | 2002-08-22 15:24:03 +0000 | [diff] [blame] | 41 | " and while processing URL /" |
| 42 | |
| 43 | ---- |
| 44 | message = "recv() failed"; |
| 45 | errno = 32; |
| 46 | ngx_http_proxy_error_context_t: |
| 47 | action = "reading headers from server %s for client %s and " |
| 48 | "while processing %s" |
| 49 | backend = "127.0.0.1"; |
| 50 | peer = "192.168.1.1"; |
| 51 | context = "URL /" |
| 52 | |
| 53 | "[2002/08/20 12:00:00] [error] 412#3: recv() failed (32: Broken pipe)" |
| 54 | " while reading headers from backend 127.0.0.1" |
| 55 | " for client 192.168.1.1 and while processing URL /" |
| 56 | |
| 57 | ---- |
| 58 | "[alert] 412#3: ngx_alloc: malloc() 102400 bytes failed (12: Cannot " |
| 59 | "allocate memory) while reading request headers from client 192.168.1.1" |
| 60 | " and while processing URL /" |
Igor Sysoev | 2b54238 | 2002-08-20 14:48:28 +0000 | [diff] [blame] | 61 | |
| 62 | |
| 63 | OLD: |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 64 | "... while ", action = "reading client request headers" |
| 65 | "... while reading client request headers" |
| 66 | "... while ", action = "reading client request headers" |
| 67 | context: pop3 user account |
| 68 | "... while reading client command for 'john_doe'" |
| 69 | */ |
| 70 | |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 71 | |
Igor Sysoev | 10fc9ef | 2003-10-27 08:53:49 +0000 | [diff] [blame] | 72 | typedef size_t (*ngx_log_handler_pt) (void *ctx, char *buf, size_t len); |
| 73 | |
| 74 | |
Igor Sysoev | 160d774 | 2003-11-19 16:26:41 +0000 | [diff] [blame] | 75 | struct ngx_log_s { |
Igor Sysoev | 10fc9ef | 2003-10-27 08:53:49 +0000 | [diff] [blame] | 76 | int log_level; |
| 77 | ngx_open_file_t *file; |
| 78 | void *data; |
| 79 | ngx_log_handler_pt handler; |
Igor Sysoev | 160d774 | 2003-11-19 16:26:41 +0000 | [diff] [blame] | 80 | }; |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 81 | |
| 82 | #define MAX_ERROR_STR 2048 |
| 83 | |
| 84 | #define _ , |
| 85 | |
| 86 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 87 | /*********************************/ |
| 88 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 89 | #if (HAVE_GCC_VARIADIC_MACROS) |
| 90 | |
| 91 | #define HAVE_VARIADIC_MACROS 1 |
| 92 | |
| 93 | #define ngx_log_error(level, log, args...) \ |
| 94 | if (log->log_level >= level) ngx_log_error_core(level, log, args) |
| 95 | |
Igor Sysoev | 4e5e117 | 2002-08-22 15:24:03 +0000 | [diff] [blame] | 96 | #if (NGX_DEBUG) |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 97 | #define ngx_log_debug(log, args...) \ |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 98 | if (log->log_level & NGX_LOG_DEBUG) \ |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 99 | ngx_log_error_core(NGX_LOG_DEBUG, log, 0, args) |
| 100 | #else |
| 101 | #define ngx_log_debug(log, args...) |
| 102 | #endif |
| 103 | |
| 104 | #define ngx_assert(assert, fallback, log, args...) \ |
| 105 | if (!(assert)) { \ |
| 106 | if (log->log_level >= NGX_LOG_ALERT) \ |
| 107 | ngx_log_error_core(NGX_LOG_ALERT, log, 0, args); \ |
| 108 | fallback; \ |
| 109 | } |
| 110 | |
| 111 | void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, |
| 112 | const char *fmt, ...); |
| 113 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 114 | /*********************************/ |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 115 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 116 | #elif (HAVE_C99_VARIADIC_MACROS) |
| 117 | |
| 118 | #define HAVE_VARIADIC_MACROS 1 |
| 119 | |
| 120 | #define ngx_log_error(level, log, ...) \ |
| 121 | if (log->log_level >= level) ngx_log_error_core(level, log, __VA_ARGS__) |
| 122 | |
Igor Sysoev | 4e5e117 | 2002-08-22 15:24:03 +0000 | [diff] [blame] | 123 | #if (NGX_DEBUG) |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 124 | #define ngx_log_debug(log, ...) \ |
| 125 | if (log->log_level == NGX_LOG_DEBUG) \ |
| 126 | ngx_log_error_core(NGX_LOG_DEBUG, log, 0, __VA_ARGS__) |
| 127 | #else |
| 128 | #define ngx_log_debug(log, ...) |
| 129 | #endif |
| 130 | |
| 131 | #define ngx_assert(assert, fallback, log, ...) \ |
| 132 | if (!(assert)) { \ |
| 133 | if (log->log_level >= NGX_LOG_ALERT) \ |
| 134 | ngx_log_error_core(NGX_LOG_ALERT, log, 0, __VA_ARGS__); \ |
| 135 | fallback; \ |
| 136 | } |
| 137 | |
| 138 | void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, |
| 139 | const char *fmt, ...); |
| 140 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 141 | /*********************************/ |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 142 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 143 | #else /* NO VARIADIC MACROS */ |
| 144 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 145 | #define HAVE_VARIADIC_MACROS 0 |
| 146 | |
Igor Sysoev | 4e5e117 | 2002-08-22 15:24:03 +0000 | [diff] [blame] | 147 | #if (NGX_DEBUG) |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 148 | #define ngx_log_debug(log, text) \ |
| 149 | if (log->log_level == NGX_LOG_DEBUG) \ |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 150 | ngx_log_debug_core(log, 0, text) |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 151 | #else |
| 152 | #define ngx_log_debug(log, text) |
| 153 | #endif |
| 154 | |
| 155 | #define ngx_assert(assert, fallback, log, text) \ |
| 156 | if (!(assert)) { \ |
| 157 | if (log->log_level >= NGX_LOG_ALERT) \ |
| 158 | ngx_assert_core(log, text); \ |
| 159 | fallback; \ |
| 160 | } |
| 161 | |
| 162 | void ngx_log_error(int level, ngx_log_t *log, ngx_err_t err, |
| 163 | const char *fmt, ...); |
| 164 | void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, |
| 165 | const char *fmt, va_list args); |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 166 | void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...); |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 167 | void ngx_assert_core(ngx_log_t *log, const char *fmt, ...); |
| 168 | |
| 169 | |
| 170 | #endif /* VARIADIC MACROS */ |
| 171 | |
| 172 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 173 | /*********************************/ |
| 174 | |
| 175 | #if (HAVE_VARIADIC_MACROS) |
| 176 | |
| 177 | #if (NGX_DEBUG) |
| 178 | #define ngx_log_debug0(level, log, err, fmt) \ |
| 179 | if (log->log_level & level) \ |
| 180 | ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt) |
| 181 | #else |
| 182 | #define ngx_log_debug0(level, log, err, fmt) |
| 183 | #endif |
| 184 | |
| 185 | #if (NGX_DEBUG) |
| 186 | #define ngx_log_debug1(level, log, err, fmt, arg1) \ |
| 187 | if (log->log_level & level) \ |
| 188 | ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1) |
| 189 | #else |
| 190 | #define ngx_log_debug1(level, log, err, fmt, arg1) |
| 191 | #endif |
| 192 | |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 193 | #if (NGX_DEBUG) |
| 194 | #define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \ |
| 195 | if (log->log_level & level) \ |
| 196 | ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1, arg2) |
| 197 | #else |
| 198 | #define ngx_log_debug2(level, log, err, fmt, arg1, arg2) |
| 199 | #endif |
| 200 | |
| 201 | #if (NGX_DEBUG) |
Igor Sysoev | 1cd1e27 | 2003-12-19 12:45:27 +0000 | [diff] [blame] | 202 | #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) \ |
| 203 | if (log->log_level & level) \ |
| 204 | ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1, arg2, arg3) |
| 205 | #else |
| 206 | #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) |
| 207 | #endif |
| 208 | |
| 209 | #if (NGX_DEBUG) |
Igor Sysoev | 669e331 | 2003-12-22 09:40:48 +0000 | [diff] [blame] | 210 | #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) \ |
| 211 | if (log->log_level & level) \ |
| 212 | ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1, arg2, arg3, arg4) |
| 213 | #else |
| 214 | #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) |
| 215 | #endif |
| 216 | |
| 217 | #if (NGX_DEBUG) |
| 218 | #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) \ |
| 219 | if (log->log_level & level) \ |
| 220 | ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, \ |
| 221 | arg1, arg2, arg3, arg4, arg5) |
| 222 | #else |
| 223 | #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) |
| 224 | #endif |
| 225 | |
| 226 | #if (NGX_DEBUG) |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 227 | #define ngx_log_debug6(level, log, err, fmt, \ |
| 228 | arg1, arg2, arg3, arg4, arg5, arg6) \ |
| 229 | if (log->log_level & level) \ |
| 230 | ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, \ |
| 231 | arg1, arg2, arg3, arg4, arg5, arg6) |
| 232 | #else |
| 233 | #define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6) |
| 234 | #endif |
| 235 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 236 | /*********************************/ |
| 237 | |
| 238 | #else /* NO VARIADIC MACROS */ |
| 239 | |
| 240 | #if (NGX_DEBUG) |
| 241 | #define ngx_log_debug0(level, log, err, fmt) \ |
| 242 | if (log->log_level & level) \ |
| 243 | ngx_log_debug_core(log, err, fmt) |
| 244 | #else |
| 245 | #define ngx_log_debug0(level, log, err, fmt) |
| 246 | #endif |
| 247 | |
| 248 | #if (NGX_DEBUG) |
| 249 | #define ngx_log_debug1(level, log, err, fmt, arg1) \ |
| 250 | if (log->log_level & level) \ |
| 251 | ngx_log_debug_core(log, err, fmt, arg1) |
| 252 | #else |
| 253 | #define ngx_log_debug1(level, log, err, fmt, arg1) |
| 254 | #endif |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 255 | |
| 256 | #if (NGX_DEBUG) |
| 257 | #define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \ |
| 258 | if (log->log_level & level) \ |
| 259 | ngx_log_debug_core(log, err, fmt, arg1, arg2) |
| 260 | #else |
| 261 | #define ngx_log_debug2(level, log, err, fmt, arg1, arg2) |
| 262 | #endif |
| 263 | |
| 264 | #if (NGX_DEBUG) |
Igor Sysoev | 1cd1e27 | 2003-12-19 12:45:27 +0000 | [diff] [blame] | 265 | #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) \ |
| 266 | if (log->log_level & level) \ |
| 267 | ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3) |
| 268 | #else |
| 269 | #define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) |
| 270 | #endif |
| 271 | |
| 272 | #if (NGX_DEBUG) |
Igor Sysoev | 669e331 | 2003-12-22 09:40:48 +0000 | [diff] [blame] | 273 | #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) \ |
| 274 | if (log->log_level & level) \ |
| 275 | ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4) |
| 276 | #else |
| 277 | #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) |
| 278 | #endif |
| 279 | |
| 280 | #if (NGX_DEBUG) |
| 281 | #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) \ |
| 282 | if (log->log_level & level) \ |
| 283 | ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5) |
| 284 | #else |
| 285 | #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) |
| 286 | #endif |
| 287 | |
| 288 | #if (NGX_DEBUG) |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 289 | #define ngx_log_debug6(level, log, err, fmt, \ |
| 290 | arg1, arg2, arg3, arg4, arg5, arg6) \ |
| 291 | if (log->log_level & level) \ |
| 292 | ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6) |
| 293 | #else |
| 294 | #define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6) |
| 295 | #endif |
| 296 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 297 | #endif |
| 298 | |
| 299 | |
| 300 | /*********************************/ |
| 301 | |
Igor Sysoev | be2cfc3 | 2003-06-15 18:32:13 +0000 | [diff] [blame] | 302 | #define ngx_log_alloc_log(pool, log) ngx_palloc(pool, log, sizeof(ngx_log_t)) |
| 303 | #define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t)) |
| 304 | |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 305 | ngx_log_t *ngx_log_init_errlog(); |
Igor Sysoev | 5f80078 | 2003-12-08 20:48:12 +0000 | [diff] [blame] | 306 | ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args); |
Igor Sysoev | 96c56c9 | 2003-07-02 14:41:17 +0000 | [diff] [blame] | 307 | |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 308 | |
| 309 | extern ngx_module_t ngx_errlog_module; |
| 310 | |
| 311 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 312 | #endif /* _NGX_LOG_H_INCLUDED_ */ |