[nginx] Mail: error_log support.

Vladimir Homutov vl at nginx.com
Sun Apr 26 07:28:52 UTC 2015


details:   http://hg.nginx.org/nginx/rev/fc99323a3d79
branches:  
changeset: 6130:fc99323a3d79
user:      Vladimir Homutov <vl at nginx.com>
date:      Fri Feb 20 15:31:37 2015 +0300
description:
Mail: error_log support.

diffstat:

 src/mail/ngx_mail.c             |  16 +++++++++-------
 src/mail/ngx_mail.h             |   1 +
 src/mail/ngx_mail_core_module.c |  27 +++++++++++++++++++++++++++
 src/mail/ngx_mail_handler.c     |  29 +++++++++++++++++------------
 4 files changed, 54 insertions(+), 19 deletions(-)

diffs (156 lines):

diff -r 187aa751ad62 -r fc99323a3d79 src/mail/ngx_mail.c
--- a/src/mail/ngx_mail.c	Sat Apr 25 22:44:02 2015 +0300
+++ b/src/mail/ngx_mail.c	Fri Feb 20 15:31:37 2015 +0300
@@ -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
             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;
 
diff -r 187aa751ad62 -r fc99323a3d79 src/mail/ngx_mail.h
--- a/src/mail/ngx_mail.h	Sat Apr 25 22:44:02 2015 +0300
+++ b/src/mail/ngx_mail.h	Fri Feb 20 15:31:37 2015 +0300
@@ -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;
diff -r 187aa751ad62 -r fc99323a3d79 src/mail/ngx_mail_core_module.c
--- a/src/mail/ngx_mail_core_module.c	Sat Apr 25 22:44:02 2015 +0300
+++ b/src/mail/ngx_mail_core_module.c	Fri Feb 20 15:31:37 2015 +0300
@@ -21,6 +21,8 @@ static char *ngx_mail_core_listen(ngx_co
     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_comm
       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
      * 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 
         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;
@@ -601,6 +619,15 @@ ngx_mail_core_protocol(ngx_conf_t *cf, n
 
 
 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)
 {
     ngx_mail_core_srv_conf_t  *cscf = conf;
diff -r 187aa751ad62 -r fc99323a3d79 src/mail/ngx_mail_handler.c
--- a/src/mail/ngx_mail_handler.c	Sat Apr 25 22:44:02 2015 +0300
+++ b/src/mail/ngx_mail_handler.c	Fri Feb 20 15:31:37 2015 +0300
@@ -24,19 +24,20 @@ static ngx_int_t ngx_mail_verify_cert(ng
 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_
     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",



More information about the nginx-devel mailing list