mirror of
https://github.com/nginx/nginx.git
synced 2024-11-28 08:09:00 +08:00
Core: consolidated log-related code.
The stderr redirection code is moved to ngx_log_redirect_stderr(). The opening of the default log code is moved to ngx_log_open_default().
This commit is contained in:
parent
f41c91511d
commit
dd3e13eef0
@ -387,13 +387,8 @@ main(int argc, char *const *argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!cycle->log_use_stderr && cycle->log->file->fd != ngx_stderr) {
|
||||
|
||||
if (ngx_set_stderr(cycle->log->file->fd) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
||||
ngx_set_stderr_n " failed");
|
||||
return 1;
|
||||
}
|
||||
if (ngx_log_redirect_stderr(cycle) != NGX_OK) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (log->file->fd != ngx_stderr) {
|
||||
|
@ -36,8 +36,6 @@ ngx_tls_key_t ngx_core_tls_key;
|
||||
static ngx_connection_t dumb;
|
||||
/* STUB */
|
||||
|
||||
static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
|
||||
|
||||
|
||||
ngx_cycle_t *
|
||||
ngx_init_cycle(ngx_cycle_t *old_cycle)
|
||||
@ -338,13 +336,8 @@ 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;
|
||||
}
|
||||
|
||||
cycle->new_log.log_level = NGX_LOG_ERR;
|
||||
if (ngx_log_open_default(cycle) != NGX_OK) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
/* open the new files */
|
||||
@ -583,13 +576,8 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
|
||||
|
||||
/* commit the new cycle configuration */
|
||||
|
||||
if (!ngx_use_stderr && !cycle->log_use_stderr
|
||||
&& cycle->log->file->fd != ngx_stderr)
|
||||
{
|
||||
if (ngx_set_stderr(cycle->log->file->fd) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
ngx_set_stderr_n " failed");
|
||||
}
|
||||
if (!ngx_use_stderr) {
|
||||
(void) ngx_log_redirect_stderr(cycle);
|
||||
}
|
||||
|
||||
pool->log = cycle->log;
|
||||
@ -1230,13 +1218,7 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
|
||||
file[i].fd = fd;
|
||||
}
|
||||
|
||||
if (!cycle->log_use_stderr && cycle->log->file->fd != ngx_stderr) {
|
||||
|
||||
if (ngx_set_stderr(cycle->log->file->fd) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
ngx_set_stderr_n " failed");
|
||||
}
|
||||
}
|
||||
(void) ngx_log_redirect_stderr(cycle);
|
||||
}
|
||||
|
||||
|
||||
|
@ -363,6 +363,48 @@ ngx_log_init(u_char *prefix)
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_log_open_default(ngx_cycle_t *cycle)
|
||||
{
|
||||
static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
|
||||
|
||||
if (cycle->new_log.file == NULL) {
|
||||
cycle->new_log.file = ngx_conf_open_file(cycle, &error_log);
|
||||
if (cycle->new_log.file == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
cycle->new_log.log_level = NGX_LOG_ERR;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_log_redirect_stderr(ngx_cycle_t *cycle)
|
||||
{
|
||||
ngx_fd_t fd;
|
||||
|
||||
if (cycle->log_use_stderr) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
fd = cycle->log->file->fd;
|
||||
|
||||
if (fd != ngx_stderr) {
|
||||
if (ngx_set_stderr(fd) == NGX_FILE_ERROR) {
|
||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
||||
ngx_set_stderr_n " failed");
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
|
||||
{
|
||||
|
@ -225,6 +225,8 @@ ngx_log_t *ngx_log_init(u_char *prefix);
|
||||
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);
|
||||
ngx_int_t ngx_log_open_default(ngx_cycle_t *cycle);
|
||||
ngx_int_t ngx_log_redirect_stderr(ngx_cycle_t *cycle);
|
||||
char *ngx_log_set_log(ngx_conf_t *cf, ngx_log_t **head);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user