*) 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
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 2662e5f..6442437 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -858,7 +858,7 @@
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 @@
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;
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index 2398d51..19344ab 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -248,6 +248,8 @@
continue;
}
+ ls[i].log = *ls[i].logp;
+
if (ls[i].inherited) {
/* TODO: close on exit */
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h
index cc6a929..de0ef41 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -34,6 +34,7 @@
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 */
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index 15f8e8d..251892b 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -82,6 +82,7 @@
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 @@
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 @@
}
+ 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 @@
#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 */
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index b4007d4..e390588 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -38,7 +38,7 @@
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;
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 924c819..770a590 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -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 @@
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_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 @@
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 @@
}
}
- 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 @@
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);
}
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index f5335ba..b736aa2 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -196,8 +196,8 @@
/*********************************/
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);
diff --git a/src/core/ngx_resolver.c b/src/core/ngx_resolver.c
index f58fb5b..2b53ee0 100644
--- a/src/core/ngx_resolver.c
+++ b/src/core/ngx_resolver.c
@@ -131,14 +131,14 @@
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 @@
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;
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 5cd0ee1..5e487e7 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -1746,7 +1746,7 @@
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;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 825c839..4b300df 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1292,10 +1292,10 @@
}
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 @@
* 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 @@
}
}
- 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_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);
}
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 546ebbb..2c4e45a 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -377,7 +377,7 @@
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;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index d06c6dd..9cdd92d 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -420,9 +420,9 @@
#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 @@
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;
diff --git a/src/mail/ngx_mail.c b/src/mail/ngx_mail.c
index aa77364..1d6b78b 100644
--- a/src/mail/ngx_mail.c
+++ b/src/mail/ngx_mail.c
@@ -313,11 +313,10 @@
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) {