Mercurial > hg > nginx
comparison src/core/ngx_log.c @ 2785:d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
error_log with zero level, and r2447, r2466, r2467 were not enough
*) remove bogus "stderr" level
*) some functions and fields renames
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 30 Apr 2009 13:53:42 +0000 |
parents | 7a44b1932741 |
children | dd1570b6f237 |
comparison
equal
deleted
inserted
replaced
2784:c2230102df6f | 2785:d478379e51ac |
---|---|
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"), |
343 return &ngx_log; | 343 return &ngx_log; |
344 } | 344 } |
345 | 345 |
346 | 346 |
347 ngx_log_t * | 347 ngx_log_t * |
348 ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name) | 348 ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name) |
349 { | 349 { |
350 ngx_log_t *log; | 350 ngx_log_t *log; |
351 | 351 |
352 log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)); | 352 log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)); |
353 if (log == NULL) { | 353 if (log == NULL) { |
362 return log; | 362 return log; |
363 } | 363 } |
364 | 364 |
365 | 365 |
366 char * | 366 char * |
367 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) |
368 { | 368 { |
369 ngx_uint_t i, n, d; | 369 ngx_uint_t i, n, d; |
370 ngx_str_t *value; | 370 ngx_str_t *value; |
371 | 371 |
372 value = cf->args->elts; | 372 value = cf->args->elts; |
407 "invalid log level \"%V\"", &value[i]); | 407 "invalid log level \"%V\"", &value[i]); |
408 return NGX_CONF_ERROR; | 408 return NGX_CONF_ERROR; |
409 } | 409 } |
410 } | 410 } |
411 | 411 |
412 if (log->log_level == 0) { | 412 if (log->log_level == NGX_LOG_DEBUG) { |
413 log->log_level = NGX_LOG_ERR; | |
414 | |
415 } else if (log->log_level == NGX_LOG_DEBUG) { | |
416 log->log_level = NGX_LOG_DEBUG_ALL; | 413 log->log_level = NGX_LOG_DEBUG_ALL; |
417 } | 414 } |
418 | 415 |
419 return NGX_CONF_OK; | 416 return NGX_CONF_OK; |
420 } | 417 } |
421 | 418 |
422 | 419 |
423 static char * | 420 static char * |
424 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) |
425 { | 422 { |
426 ngx_str_t *value; | 423 ngx_str_t *value, name; |
424 | |
425 if (cf->cycle->new_log.file) { | |
426 return "is duplicate"; | |
427 } | |
427 | 428 |
428 value = cf->args->elts; | 429 value = cf->args->elts; |
429 | 430 |
430 if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) { | 431 if (ngx_strcmp(value[1].data, "stderr") == 0) { |
431 cf->cycle->new_log->file->fd = ngx_stderr; | 432 name.len = 0; |
432 cf->cycle->new_log->file->name.len = 0; | 433 name.data = NULL; |
433 cf->cycle->new_log->file->name.data = NULL; | |
434 | 434 |
435 } else { | 435 } else { |
436 cf->cycle->new_log->file->name = value[1]; | 436 name = value[1]; |
437 | 437 } |
438 if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name, 0) | 438 |
439 != NGX_OK) | 439 cf->cycle->new_log.file = ngx_conf_open_file(cf->cycle, &name); |
440 { | 440 if (cf->cycle->new_log.file == NULL) { |
441 return NGX_CONF_ERROR; | 441 return NULL; |
442 } | 442 } |
443 } | 443 |
444 | 444 if (cf->args->nelts == 2) { |
445 return ngx_set_error_log_levels(cf, cf->cycle->new_log); | 445 cf->cycle->new_log.log_level = NGX_LOG_ERR; |
446 } | 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 } |