Mercurial > hg > nginx-vendor-0-8
comparison src/core/ngx_log.c @ 484:ed5e10fb40fc NGINX_0_7_54
nginx 0.7.54
*) Feature: the ngx_http_image_filter_module.
*) Feature: the "proxy_ignore_headers" and "fastcgi_ignore_headers"
directives.
*) Bugfix: a segmentation fault might occur in worker process, if an
"open_file_cache_errors off" directive was used; the bug had
appeared in 0.7.53.
*) Bugfix: the "port_in_redirect off" directive did not work; the bug
had appeared in 0.7.39.
*) Bugfix: improve handling of "select" method errors.
*) Bugfix: of "select() failed (10022: ...)" error in nginx/Windows.
*) Bugfix: in error text descriptions in nginx/Windows; the bug had
appeared in 0.7.53.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 01 May 2009 00:00:00 +0400 |
parents | 392c16f2d858 |
children | 8246d8a2c2be |
comparison
equal
deleted
inserted
replaced
483:0a2f4b42ddad | 484:ed5e10fb40fc |
---|---|
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 | 9 |
10 | 10 |
11 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 11 static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
12 | 12 |
13 | 13 |
14 static ngx_command_t ngx_errlog_commands[] = { | 14 static ngx_command_t ngx_errlog_commands[] = { |
15 | 15 |
16 {ngx_string("error_log"), | 16 {ngx_string("error_log"), |
17 NGX_MAIN_CONF|NGX_CONF_1MORE, | 17 NGX_MAIN_CONF|NGX_CONF_1MORE, |
18 ngx_set_error_log, | 18 ngx_error_log, |
19 0, | 19 0, |
20 0, | 20 0, |
21 NULL}, | 21 NULL}, |
22 | 22 |
23 ngx_null_command | 23 ngx_null_command |
51 static ngx_open_file_t ngx_log_file; | 51 static ngx_open_file_t ngx_log_file; |
52 ngx_uint_t ngx_use_stderr = 1; | 52 ngx_uint_t ngx_use_stderr = 1; |
53 | 53 |
54 | 54 |
55 static ngx_str_t err_levels[] = { | 55 static ngx_str_t err_levels[] = { |
56 ngx_string("stderr"), | 56 ngx_null_string, |
57 ngx_string("emerg"), | 57 ngx_string("emerg"), |
58 ngx_string("alert"), | 58 ngx_string("alert"), |
59 ngx_string("crit"), | 59 ngx_string("crit"), |
60 ngx_string("error"), | 60 ngx_string("error"), |
61 ngx_string("warn"), | 61 ngx_string("warn"), |
99 ngx_memcpy(errstr, ngx_cached_err_log_time.data, | 99 ngx_memcpy(errstr, ngx_cached_err_log_time.data, |
100 ngx_cached_err_log_time.len); | 100 ngx_cached_err_log_time.len); |
101 | 101 |
102 p = errstr + ngx_cached_err_log_time.len; | 102 p = errstr + ngx_cached_err_log_time.len; |
103 | 103 |
104 p = ngx_snprintf(p, last - p, " [%V] ", &err_levels[level]); | 104 p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]); |
105 | 105 |
106 /* pid#tid */ | 106 /* pid#tid */ |
107 p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ", | 107 p = ngx_slprintf(p, last, "%P#" NGX_TID_T_FMT ": ", |
108 ngx_log_pid, ngx_log_tid); | 108 ngx_log_pid, ngx_log_tid); |
109 | 109 |
110 if (log->connection) { | 110 if (log->connection) { |
111 p = ngx_snprintf(p, last - p, "*%uA ", log->connection); | 111 p = ngx_slprintf(p, last, "*%uA ", log->connection); |
112 } | 112 } |
113 | 113 |
114 msg = p; | 114 msg = p; |
115 | 115 |
116 #if (NGX_HAVE_VARIADIC_MACROS) | 116 #if (NGX_HAVE_VARIADIC_MACROS) |
117 | 117 |
118 va_start(args, fmt); | 118 va_start(args, fmt); |
119 p = ngx_vsnprintf(p, last - p, fmt, args); | 119 p = ngx_vslprintf(p, last, fmt, args); |
120 va_end(args); | 120 va_end(args); |
121 | 121 |
122 #else | 122 #else |
123 | 123 |
124 p = ngx_vsnprintf(p, last - p, fmt, args); | 124 p = ngx_vslprintf(p, last, fmt, args); |
125 | 125 |
126 #endif | 126 #endif |
127 | 127 |
128 if (err) { | 128 if (err) { |
129 | 129 p = ngx_log_errno(p, last, err); |
130 if (p > last - 50) { | |
131 | |
132 /* leave a space for an error code */ | |
133 | |
134 p = last - 50; | |
135 *p++ = '.'; | |
136 *p++ = '.'; | |
137 *p++ = '.'; | |
138 } | |
139 | |
140 #if (NGX_WIN32) | |
141 p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000) | |
142 ? " (%d: " : " (%Xd: ", err); | |
143 #else | |
144 p = ngx_snprintf(p, last - p, " (%d: ", err); | |
145 #endif | |
146 | |
147 p = ngx_strerror_r(err, p, last - p); | |
148 | |
149 if (p < last) { | |
150 *p++ = ')'; | |
151 } | |
152 } | 130 } |
153 | 131 |
154 if (level != NGX_LOG_DEBUG && log->handler) { | 132 if (level != NGX_LOG_DEBUG && log->handler) { |
155 p = log->handler(log, p, last - p); | 133 p = log->handler(log, p, last - p); |
156 } | 134 } |
172 | 150 |
173 msg -= (err_levels[level].len + 4); | 151 msg -= (err_levels[level].len + 4); |
174 | 152 |
175 (void) ngx_sprintf(msg, "[%V]: ", &err_levels[level]); | 153 (void) ngx_sprintf(msg, "[%V]: ", &err_levels[level]); |
176 | 154 |
177 (void) ngx_write_fd(ngx_stderr, msg, p - msg); | 155 (void) ngx_write_console(ngx_stderr, msg, p - msg); |
178 } | 156 } |
179 | 157 |
180 | 158 |
181 #if !(NGX_HAVE_VARIADIC_MACROS) | 159 #if !(NGX_HAVE_VARIADIC_MACROS) |
182 | 160 |
228 { | 206 { |
229 u_char *p, *last; | 207 u_char *p, *last; |
230 va_list args; | 208 va_list args; |
231 u_char errstr[NGX_MAX_ERROR_STR]; | 209 u_char errstr[NGX_MAX_ERROR_STR]; |
232 | 210 |
211 last = errstr + NGX_MAX_ERROR_STR; | |
212 | |
233 va_start(args, fmt); | 213 va_start(args, fmt); |
234 p = ngx_vsnprintf(errstr, NGX_MAX_ERROR_STR, fmt, args); | 214 p = ngx_vslprintf(errstr, last, fmt, args); |
235 va_end(args); | 215 va_end(args); |
236 | 216 |
237 if (p > errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE) { | |
238 p = errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE; | |
239 } | |
240 | |
241 if (err) { | 217 if (err) { |
242 | 218 p = ngx_log_errno(p, last, err); |
243 last = errstr + NGX_MAX_ERROR_STR; | 219 } |
244 | 220 |
245 if (p > last - 50) { | 221 if (p > last - NGX_LINEFEED_SIZE) { |
246 | 222 p = last - NGX_LINEFEED_SIZE; |
247 /* leave a space for an error code */ | 223 } |
248 | 224 |
249 p = last - 50; | 225 ngx_linefeed(p); |
250 *p++ = '.'; | 226 |
251 *p++ = '.'; | 227 (void) ngx_write_console(ngx_stderr, errstr, p - errstr); |
252 *p++ = '.'; | 228 } |
253 } | 229 |
230 | |
231 u_char * | |
232 ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err) | |
233 { | |
234 if (buf > last - 50) { | |
235 | |
236 /* leave a space for an error code */ | |
237 | |
238 buf = last - 50; | |
239 *buf++ = '.'; | |
240 *buf++ = '.'; | |
241 *buf++ = '.'; | |
242 } | |
254 | 243 |
255 #if (NGX_WIN32) | 244 #if (NGX_WIN32) |
256 p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000) | 245 buf = ngx_slprintf(buf, last, ((unsigned) err < 0x80000000) |
257 ? " (%d: " : " (%Xd: ", err); | 246 ? " (%d: " : " (%Xd: ", err); |
258 #else | 247 #else |
259 p = ngx_snprintf(p, last - p, " (%d: ", err); | 248 buf = ngx_slprintf(buf, last, " (%d: ", err); |
260 #endif | 249 #endif |
261 | 250 |
262 p = ngx_strerror_r(err, p, last - p); | 251 buf = ngx_strerror_r(err, buf, last - buf); |
263 | 252 |
264 if (p < last) { | 253 if (buf < last) { |
265 *p++ = ')'; | 254 *buf++ = ')'; |
266 } | 255 } |
267 } | 256 |
268 | 257 return buf; |
269 ngx_linefeed(p); | |
270 | |
271 (void) ngx_write_fd(ngx_stderr, errstr, p - errstr); | |
272 } | 258 } |
273 | 259 |
274 | 260 |
275 ngx_log_t * | 261 ngx_log_t * |
276 ngx_log_init(u_char *prefix) | 262 ngx_log_init(u_char *prefix) |
300 #if (NGX_WIN32) | 286 #if (NGX_WIN32) |
301 if (name[1] != ':') { | 287 if (name[1] != ':') { |
302 #else | 288 #else |
303 if (name[0] != '/') { | 289 if (name[0] != '/') { |
304 #endif | 290 #endif |
305 plen = 0; | |
306 | 291 |
307 if (prefix) { | 292 if (prefix) { |
308 plen = ngx_strlen(prefix); | 293 plen = ngx_strlen(prefix); |
309 | 294 |
295 } else { | |
310 #ifdef NGX_PREFIX | 296 #ifdef NGX_PREFIX |
311 } else { | |
312 prefix = (u_char *) NGX_PREFIX; | 297 prefix = (u_char *) NGX_PREFIX; |
313 plen = ngx_strlen(prefix); | 298 plen = ngx_strlen(prefix); |
299 #else | |
300 plen = 0; | |
314 #endif | 301 #endif |
315 } | 302 } |
316 | 303 |
317 if (plen) { | 304 if (plen) { |
318 name = malloc(plen + nlen + 2); | 305 name = malloc(plen + nlen + 2); |
356 return &ngx_log; | 343 return &ngx_log; |
357 } | 344 } |
358 | 345 |
359 | 346 |
360 ngx_log_t * | 347 ngx_log_t * |
361 ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name) | 348 ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name) |
362 { | 349 { |
363 ngx_log_t *log; | 350 ngx_log_t *log; |
364 | 351 |
365 log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)); | 352 log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)); |
366 if (log == NULL) { | 353 if (log == NULL) { |
375 return log; | 362 return log; |
376 } | 363 } |
377 | 364 |
378 | 365 |
379 char * | 366 char * |
380 ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log) | 367 ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log) |
381 { | 368 { |
382 ngx_uint_t i, n, d; | 369 ngx_uint_t i, n, d; |
383 ngx_str_t *value; | 370 ngx_str_t *value; |
384 | 371 |
385 value = cf->args->elts; | 372 value = cf->args->elts; |
420 "invalid log level \"%V\"", &value[i]); | 407 "invalid log level \"%V\"", &value[i]); |
421 return NGX_CONF_ERROR; | 408 return NGX_CONF_ERROR; |
422 } | 409 } |
423 } | 410 } |
424 | 411 |
425 if (log->log_level == 0) { | 412 if (log->log_level == NGX_LOG_DEBUG) { |
426 log->log_level = NGX_LOG_ERR; | |
427 | |
428 } else if (log->log_level == NGX_LOG_DEBUG) { | |
429 log->log_level = NGX_LOG_DEBUG_ALL; | 413 log->log_level = NGX_LOG_DEBUG_ALL; |
430 } | 414 } |
431 | 415 |
432 return NGX_CONF_OK; | 416 return NGX_CONF_OK; |
433 } | 417 } |
434 | 418 |
435 | 419 |
436 static char * | 420 static char * |
437 ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 421 ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
438 { | 422 { |
439 ngx_str_t *value; | 423 ngx_str_t *value, name; |
424 | |
425 if (cf->cycle->new_log.file) { | |
426 return "is duplicate"; | |
427 } | |
440 | 428 |
441 value = cf->args->elts; | 429 value = cf->args->elts; |
442 | 430 |
443 if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) { | 431 if (ngx_strcmp(value[1].data, "stderr") == 0) { |
444 cf->cycle->new_log->file->fd = ngx_stderr; | 432 name.len = 0; |
445 cf->cycle->new_log->file->name.len = 0; | 433 name.data = NULL; |
446 cf->cycle->new_log->file->name.data = NULL; | |
447 | 434 |
448 } else { | 435 } else { |
449 cf->cycle->new_log->file->name = value[1]; | 436 name = value[1]; |
450 | 437 } |
451 if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name, 0) | 438 |
452 != NGX_OK) | 439 cf->cycle->new_log.file = ngx_conf_open_file(cf->cycle, &name); |
453 { | 440 if (cf->cycle->new_log.file == NULL) { |
454 return NGX_CONF_ERROR; | 441 return NULL; |
455 } | 442 } |
456 } | 443 |
457 | 444 if (cf->args->nelts == 2) { |
458 return ngx_set_error_log_levels(cf, cf->cycle->new_log); | 445 cf->cycle->new_log.log_level = NGX_LOG_ERR; |
459 } | 446 return NGX_CONF_OK; |
447 } | |
448 | |
449 cf->cycle->new_log.log_level = 0; | |
450 | |
451 return ngx_log_set_levels(cf, &cf->cycle->new_log); | |
452 } |