mirror of
https://github.com/nginx/nginx.git
synced 2025-06-11 04:12:40 +08:00
*) 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
This commit is contained in:
parent
06d4aa1883
commit
0cd76ea290
@ -858,7 +858,7 @@ ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
|
||||
full.data = NULL;
|
||||
#endif
|
||||
|
||||
if (name && name->len) {
|
||||
if (name->len) {
|
||||
full = *name;
|
||||
|
||||
if (ngx_conf_full_name(cycle, &full, 0) != NGX_OK) {
|
||||
@ -894,14 +894,13 @@ ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (name && name->len) {
|
||||
if (name->len) {
|
||||
file->fd = NGX_INVALID_FILE;
|
||||
file->name = full;
|
||||
|
||||
} else {
|
||||
file->fd = ngx_stderr;
|
||||
file->name.len = 0;
|
||||
file->name.data = NULL;
|
||||
file->name = *name;
|
||||
}
|
||||
|
||||
file->buffer = NULL;
|
||||
|
@ -248,6 +248,8 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle)
|
||||
continue;
|
||||
}
|
||||
|
||||
ls[i].log = *ls[i].logp;
|
||||
|
||||
if (ls[i].inherited) {
|
||||
|
||||
/* TODO: close on exit */
|
||||
|
@ -34,6 +34,7 @@ struct ngx_listening_s {
|
||||
void *servers; /* array of ngx_http_in_addr_t, for example */
|
||||
|
||||
ngx_log_t log;
|
||||
ngx_log_t *logp;
|
||||
|
||||
size_t pool_size;
|
||||
/* should be here because of the AcceptEx() preread */
|
||||
|
@ -82,6 +82,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
|
||||
|
||||
cycle->pool = pool;
|
||||
cycle->log = log;
|
||||
cycle->new_log.log_level = NGX_LOG_ERR;
|
||||
cycle->old_cycle = old_cycle;
|
||||
|
||||
cycle->conf_prefix.len = old_cycle->conf_prefix.len;
|
||||
@ -165,14 +166,6 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
cycle->new_log = ngx_log_create_errlog(cycle, &error_log);
|
||||
if (cycle->new_log == NULL) {
|
||||
ngx_destroy_pool(pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
|
||||
|
||||
cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
|
||||
@ -336,6 +329,13 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
|
||||
}
|
||||
|
||||
|
||||
if (cycle->new_log.file == NULL) {
|
||||
cycle->new_log.file = ngx_conf_open_file(cycle, &error_log);
|
||||
if (cycle->new_log.file == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
/* open the new files */
|
||||
|
||||
part = &cycle->open_files.part;
|
||||
@ -382,12 +382,8 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
|
||||
#endif
|
||||
}
|
||||
|
||||
cycle->log = cycle->new_log;
|
||||
pool->log = cycle->new_log;
|
||||
|
||||
if (cycle->log->log_level == 0) {
|
||||
cycle->log->log_level = NGX_LOG_ERR;
|
||||
}
|
||||
cycle->log = &cycle->new_log;
|
||||
pool->log = &cycle->new_log;
|
||||
|
||||
|
||||
/* create shared memory */
|
||||
|
@ -38,7 +38,7 @@ struct ngx_cycle_s {
|
||||
ngx_pool_t *pool;
|
||||
|
||||
ngx_log_t *log;
|
||||
ngx_log_t *new_log;
|
||||
ngx_log_t new_log;
|
||||
|
||||
ngx_connection_t **files;
|
||||
ngx_connection_t *free_connections;
|
||||
|
@ -8,14 +8,14 @@
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
||||
|
||||
static ngx_command_t ngx_errlog_commands[] = {
|
||||
|
||||
{ngx_string("error_log"),
|
||||
NGX_MAIN_CONF|NGX_CONF_1MORE,
|
||||
ngx_set_error_log,
|
||||
ngx_error_log,
|
||||
0,
|
||||
0,
|
||||
NULL},
|
||||
@ -53,7 +53,7 @@ ngx_uint_t ngx_use_stderr = 1;
|
||||
|
||||
|
||||
static ngx_str_t err_levels[] = {
|
||||
ngx_string("stderr"),
|
||||
ngx_null_string,
|
||||
ngx_string("emerg"),
|
||||
ngx_string("alert"),
|
||||
ngx_string("crit"),
|
||||
@ -345,7 +345,7 @@ ngx_log_init(u_char *prefix)
|
||||
|
||||
|
||||
ngx_log_t *
|
||||
ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name)
|
||||
ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
|
||||
{
|
||||
ngx_log_t *log;
|
||||
|
||||
@ -364,7 +364,7 @@ ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name)
|
||||
|
||||
|
||||
char *
|
||||
ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
|
||||
ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
|
||||
{
|
||||
ngx_uint_t i, n, d;
|
||||
ngx_str_t *value;
|
||||
@ -409,10 +409,7 @@ ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
|
||||
}
|
||||
}
|
||||
|
||||
if (log->log_level == 0) {
|
||||
log->log_level = NGX_LOG_ERR;
|
||||
|
||||
} else if (log->log_level == NGX_LOG_DEBUG) {
|
||||
if (log->log_level == NGX_LOG_DEBUG) {
|
||||
log->log_level = NGX_LOG_DEBUG_ALL;
|
||||
}
|
||||
|
||||
@ -421,26 +418,35 @@ ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
|
||||
|
||||
|
||||
static char *
|
||||
ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_str_t *value;
|
||||
ngx_str_t *value, name;
|
||||
|
||||
if (cf->cycle->new_log.file) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) {
|
||||
cf->cycle->new_log->file->fd = ngx_stderr;
|
||||
cf->cycle->new_log->file->name.len = 0;
|
||||
cf->cycle->new_log->file->name.data = NULL;
|
||||
if (ngx_strcmp(value[1].data, "stderr") == 0) {
|
||||
name.len = 0;
|
||||
name.data = NULL;
|
||||
|
||||
} else {
|
||||
cf->cycle->new_log->file->name = value[1];
|
||||
|
||||
if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name, 0)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
name = value[1];
|
||||
}
|
||||
|
||||
return ngx_set_error_log_levels(cf, cf->cycle->new_log);
|
||||
cf->cycle->new_log.file = ngx_conf_open_file(cf->cycle, &name);
|
||||
if (cf->cycle->new_log.file == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cf->args->nelts == 2) {
|
||||
cf->cycle->new_log.log_level = NGX_LOG_ERR;
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
cf->cycle->new_log.log_level = 0;
|
||||
|
||||
return ngx_log_set_levels(cf, &cf->cycle->new_log);
|
||||
}
|
||||
|
@ -196,8 +196,8 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
|
||||
/*********************************/
|
||||
|
||||
ngx_log_t *ngx_log_init(u_char *prefix);
|
||||
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name);
|
||||
char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);
|
||||
ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name);
|
||||
char *ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log);
|
||||
void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
|
||||
void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
|
||||
u_char *ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err);
|
||||
|
@ -131,14 +131,14 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_peer_addr_t *addr)
|
||||
|
||||
r->event->handler = ngx_resolver_resend_handler;
|
||||
r->event->data = r;
|
||||
r->event->log = cf->cycle->new_log;
|
||||
r->event->log = &cf->cycle->new_log;
|
||||
r->ident = -1;
|
||||
|
||||
r->resend_timeout = 5;
|
||||
r->expire = 30;
|
||||
r->valid = 300;
|
||||
|
||||
r->log = cf->cycle->new_log;
|
||||
r->log = &cf->cycle->new_log;
|
||||
r->log_level = NGX_LOG_ALERT;
|
||||
|
||||
if (addr) {
|
||||
@ -152,7 +152,7 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_peer_addr_t *addr)
|
||||
uc->sockaddr = addr->sockaddr;
|
||||
uc->socklen = addr->socklen;
|
||||
uc->server = addr->name;
|
||||
uc->log = cf->cycle->new_log;
|
||||
uc->log = &cf->cycle->new_log;
|
||||
}
|
||||
|
||||
return r;
|
||||
|
@ -1746,7 +1746,7 @@ ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr)
|
||||
|
||||
clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
|
||||
|
||||
ls->log = *clcf->err_log;
|
||||
ls->logp = clcf->error_log;
|
||||
ls->log.data = &ls->addr_text;
|
||||
ls->log.handler = ngx_accept_log_error;
|
||||
|
||||
|
@ -1292,10 +1292,10 @@ ngx_http_update_location_config(ngx_http_request_t *r)
|
||||
}
|
||||
|
||||
if (r == r->main) {
|
||||
r->connection->log->file = clcf->err_log->file;
|
||||
r->connection->log->file = clcf->error_log->file;
|
||||
|
||||
if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
||||
r->connection->log->log_level = clcf->err_log->log_level;
|
||||
r->connection->log->log_level = clcf->error_log->log_level;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2929,7 +2929,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
||||
* lcf->post_action = { 0, NULL };
|
||||
* lcf->types = NULL;
|
||||
* lcf->default_type = { 0, NULL };
|
||||
* lcf->err_log = NULL;
|
||||
* lcf->error_log = NULL;
|
||||
* lcf->error_pages = NULL;
|
||||
* lcf->try_files = NULL;
|
||||
* lcf->client_body_path = NULL;
|
||||
@ -3109,11 +3109,11 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
}
|
||||
}
|
||||
|
||||
if (conf->err_log == NULL) {
|
||||
if (prev->err_log) {
|
||||
conf->err_log = prev->err_log;
|
||||
if (conf->error_log == NULL) {
|
||||
if (prev->error_log) {
|
||||
conf->error_log = prev->error_log;
|
||||
} else {
|
||||
conf->err_log = cf->cycle->new_log;
|
||||
conf->error_log = &cf->cycle->new_log;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4104,14 +4104,23 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
|
||||
ngx_str_t *value;
|
||||
|
||||
if (lcf->error_log) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
lcf->err_log = ngx_log_create_errlog(cf->cycle, &value[1]);
|
||||
if (lcf->err_log == NULL) {
|
||||
lcf->error_log = ngx_log_create(cf->cycle, &value[1]);
|
||||
if (lcf->error_log == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
return ngx_set_error_log_levels(cf, lcf->err_log);
|
||||
if (cf->args->nelts == 2) {
|
||||
lcf->error_log->log_level = NGX_LOG_ERR;
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
return ngx_log_set_levels(cf, lcf->error_log);
|
||||
}
|
||||
|
||||
|
||||
|
@ -377,7 +377,7 @@ struct ngx_http_core_loc_conf_s {
|
||||
ngx_flag_t open_file_cache_errors;
|
||||
ngx_flag_t open_file_cache_events;
|
||||
|
||||
ngx_log_t *err_log;
|
||||
ngx_log_t *error_log;
|
||||
|
||||
ngx_uint_t types_hash_max_size;
|
||||
ngx_uint_t types_hash_bucket_size;
|
||||
|
@ -420,9 +420,9 @@ ngx_http_init_request(ngx_event_t *rev)
|
||||
#endif
|
||||
|
||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||
c->log->file = clcf->err_log->file;
|
||||
c->log->file = clcf->error_log->file;
|
||||
if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
||||
c->log->log_level = clcf->err_log->log_level;
|
||||
c->log->log_level = clcf->error_log->log_level;
|
||||
}
|
||||
|
||||
if (c->buffer == NULL) {
|
||||
@ -1704,10 +1704,10 @@ found:
|
||||
r->loc_conf = cscf->ctx->loc_conf;
|
||||
|
||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||
r->connection->log->file = clcf->err_log->file;
|
||||
r->connection->log->file = clcf->error_log->file;
|
||||
|
||||
if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
||||
r->connection->log->log_level = clcf->err_log->log_level;
|
||||
r->connection->log->log_level = clcf->error_log->log_level;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
|
@ -313,11 +313,10 @@ ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
ls->handler = ngx_mail_init_connection;
|
||||
ls->pool_size = 256;
|
||||
|
||||
/* STUB */
|
||||
ls->log = *cf->cycle->new_log;
|
||||
/* TODO: error_log directive */
|
||||
ls->logp = &cf->cycle->new_log;
|
||||
ls->log.data = &ls->addr_text;
|
||||
ls->log.handler = ngx_accept_log_error;
|
||||
/**/
|
||||
|
||||
imip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t));
|
||||
if (imip == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user