mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
Mail: error_log support.
This commit is contained in:
parent
df555ffce6
commit
4e010c2834
@ -339,6 +339,7 @@ ngx_mail_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports)
|
|||||||
ngx_mail_port_t *mport;
|
ngx_mail_port_t *mport;
|
||||||
ngx_mail_conf_port_t *port;
|
ngx_mail_conf_port_t *port;
|
||||||
ngx_mail_conf_addr_t *addr;
|
ngx_mail_conf_addr_t *addr;
|
||||||
|
ngx_mail_core_srv_conf_t *cscf;
|
||||||
|
|
||||||
port = ports->elts;
|
port = ports->elts;
|
||||||
for (p = 0; p < ports->nelts; p++) {
|
for (p = 0; p < ports->nelts; p++) {
|
||||||
@ -380,8 +381,9 @@ ngx_mail_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports)
|
|||||||
ls->handler = ngx_mail_init_connection;
|
ls->handler = ngx_mail_init_connection;
|
||||||
ls->pool_size = 256;
|
ls->pool_size = 256;
|
||||||
|
|
||||||
/* TODO: error_log directive */
|
cscf = addr->ctx->srv_conf[ngx_mail_core_module.ctx_index];
|
||||||
ls->logp = &cf->cycle->new_log;
|
|
||||||
|
ls->logp = cscf->error_log;
|
||||||
ls->log.data = &ls->addr_text;
|
ls->log.data = &ls->addr_text;
|
||||||
ls->log.handler = ngx_accept_log_error;
|
ls->log.handler = ngx_accept_log_error;
|
||||||
|
|
||||||
|
@ -139,6 +139,7 @@ typedef struct {
|
|||||||
ngx_int_t line;
|
ngx_int_t line;
|
||||||
|
|
||||||
ngx_resolver_t *resolver;
|
ngx_resolver_t *resolver;
|
||||||
|
ngx_log_t *error_log;
|
||||||
|
|
||||||
/* server ctx */
|
/* server ctx */
|
||||||
ngx_mail_conf_ctx_t *ctx;
|
ngx_mail_conf_ctx_t *ctx;
|
||||||
|
@ -21,6 +21,8 @@ static char *ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||||||
void *conf);
|
void *conf);
|
||||||
static char *ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
void *conf);
|
||||||
|
static char *ngx_mail_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
|
void *conf);
|
||||||
static char *ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
void *conf);
|
||||||
|
|
||||||
@ -75,6 +77,13 @@ static ngx_command_t ngx_mail_core_commands[] = {
|
|||||||
offsetof(ngx_mail_core_srv_conf_t, server_name),
|
offsetof(ngx_mail_core_srv_conf_t, server_name),
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ ngx_string("error_log"),
|
||||||
|
NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
|
||||||
|
ngx_mail_core_error_log,
|
||||||
|
NGX_MAIL_SRV_CONF_OFFSET,
|
||||||
|
0,
|
||||||
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("resolver"),
|
{ ngx_string("resolver"),
|
||||||
NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
|
NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
|
||||||
ngx_mail_core_resolver,
|
ngx_mail_core_resolver,
|
||||||
@ -161,6 +170,7 @@ ngx_mail_core_create_srv_conf(ngx_conf_t *cf)
|
|||||||
* set by ngx_pcalloc():
|
* set by ngx_pcalloc():
|
||||||
*
|
*
|
||||||
* cscf->protocol = NULL;
|
* cscf->protocol = NULL;
|
||||||
|
* cscf->error_log = NULL;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cscf->timeout = NGX_CONF_UNSET_MSEC;
|
cscf->timeout = NGX_CONF_UNSET_MSEC;
|
||||||
@ -202,6 +212,14 @@ ngx_mail_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (conf->error_log == NULL) {
|
||||||
|
if (prev->error_log) {
|
||||||
|
conf->error_log = prev->error_log;
|
||||||
|
} else {
|
||||||
|
conf->error_log = &cf->cycle->new_log;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngx_conf_merge_ptr_value(conf->resolver, prev->resolver, NULL);
|
ngx_conf_merge_ptr_value(conf->resolver, prev->resolver, NULL);
|
||||||
|
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
@ -600,6 +618,15 @@ ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *
|
||||||
|
ngx_mail_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
|
{
|
||||||
|
ngx_mail_core_srv_conf_t *cscf = conf;
|
||||||
|
|
||||||
|
return ngx_log_set_log(cf, &cscf->error_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
|
@ -33,6 +33,7 @@ ngx_mail_init_connection(ngx_connection_t *c)
|
|||||||
ngx_mail_in_addr_t *addr;
|
ngx_mail_in_addr_t *addr;
|
||||||
ngx_mail_session_t *s;
|
ngx_mail_session_t *s;
|
||||||
ngx_mail_addr_conf_t *addr_conf;
|
ngx_mail_addr_conf_t *addr_conf;
|
||||||
|
ngx_mail_core_srv_conf_t *cscf;
|
||||||
u_char text[NGX_SOCKADDR_STRLEN];
|
u_char text[NGX_SOCKADDR_STRLEN];
|
||||||
#if (NGX_HAVE_INET6)
|
#if (NGX_HAVE_INET6)
|
||||||
struct sockaddr_in6 *sin6;
|
struct sockaddr_in6 *sin6;
|
||||||
@ -133,6 +134,10 @@ ngx_mail_init_connection(ngx_connection_t *c)
|
|||||||
c->data = s;
|
c->data = s;
|
||||||
s->connection = c;
|
s->connection = c;
|
||||||
|
|
||||||
|
cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
|
||||||
|
|
||||||
|
ngx_set_connection_log(c, cscf->error_log);
|
||||||
|
|
||||||
len = ngx_sock_ntop(c->sockaddr, c->socklen, text, NGX_SOCKADDR_STRLEN, 1);
|
len = ngx_sock_ntop(c->sockaddr, c->socklen, text, NGX_SOCKADDR_STRLEN, 1);
|
||||||
|
|
||||||
ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %*s connected to %V",
|
ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %*s connected to %V",
|
||||||
|
Loading…
Reference in New Issue
Block a user