Mail: error_log support.

This commit is contained in:
Vladimir Homutov 2015-02-20 15:31:37 +03:00
parent bcf9cd2d24
commit 366a6f29e4
4 changed files with 54 additions and 19 deletions

View file

@ -334,11 +334,12 @@ found:
static char *
ngx_mail_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports)
{
ngx_uint_t i, p, last, bind_wildcard;
ngx_listening_t *ls;
ngx_mail_port_t *mport;
ngx_mail_conf_port_t *port;
ngx_mail_conf_addr_t *addr;
ngx_uint_t i, p, last, bind_wildcard;
ngx_listening_t *ls;
ngx_mail_port_t *mport;
ngx_mail_conf_port_t *port;
ngx_mail_conf_addr_t *addr;
ngx_mail_core_srv_conf_t *cscf;
port = ports->elts;
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->pool_size = 256;
/* TODO: error_log directive */
ls->logp = &cf->cycle->new_log;
cscf = addr->ctx->srv_conf[ngx_mail_core_module.ctx_index];
ls->logp = cscf->error_log;
ls->log.data = &ls->addr_text;
ls->log.handler = ngx_accept_log_error;

View file

@ -139,6 +139,7 @@ typedef struct {
ngx_int_t line;
ngx_resolver_t *resolver;
ngx_log_t *error_log;
/* server ctx */
ngx_mail_conf_ctx_t *ctx;

View file

@ -21,6 +21,8 @@ static char *ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *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);
static char *ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
@ -75,6 +77,13 @@ static ngx_command_t ngx_mail_core_commands[] = {
offsetof(ngx_mail_core_srv_conf_t, server_name),
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_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
ngx_mail_core_resolver,
@ -161,6 +170,7 @@ ngx_mail_core_create_srv_conf(ngx_conf_t *cf)
* set by ngx_pcalloc():
*
* cscf->protocol = NULL;
* cscf->error_log = NULL;
*/
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;
}
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);
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 *
ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{

View file

@ -24,19 +24,20 @@ static ngx_int_t ngx_mail_verify_cert(ngx_mail_session_t *s,
void
ngx_mail_init_connection(ngx_connection_t *c)
{
size_t len;
ngx_uint_t i;
ngx_mail_port_t *port;
struct sockaddr *sa;
struct sockaddr_in *sin;
ngx_mail_log_ctx_t *ctx;
ngx_mail_in_addr_t *addr;
ngx_mail_session_t *s;
ngx_mail_addr_conf_t *addr_conf;
u_char text[NGX_SOCKADDR_STRLEN];
size_t len;
ngx_uint_t i;
ngx_mail_port_t *port;
struct sockaddr *sa;
struct sockaddr_in *sin;
ngx_mail_log_ctx_t *ctx;
ngx_mail_in_addr_t *addr;
ngx_mail_session_t *s;
ngx_mail_addr_conf_t *addr_conf;
ngx_mail_core_srv_conf_t *cscf;
u_char text[NGX_SOCKADDR_STRLEN];
#if (NGX_HAVE_INET6)
struct sockaddr_in6 *sin6;
ngx_mail_in6_addr_t *addr6;
struct sockaddr_in6 *sin6;
ngx_mail_in6_addr_t *addr6;
#endif
@ -133,6 +134,10 @@ ngx_mail_init_connection(ngx_connection_t *c)
c->data = s;
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);
ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %*s connected to %V",