BUG report: error log separation per virtual host does not work

Igor Sysoev is at rambler-co.ru
Tue Jan 13 16:36:43 MSK 2009


On Thu, Jan 08, 2009 at 01:36:31PM +0300, Maxim Dounin wrote:

> On Wed, Jan 07, 2009 at 09:09:02PM -0800, Dan Dascalescu wrote:
> 
> > I reported this bug already at
> > http://thread.gmane.org/gmane.comp.web.nginx.english/1604/focus=1628
> > but was using the stable version of nginx. I just upgraded to the
> > latest development version, 0.7.30, and the bug is still there:
> > 
> > I want to have separate error logs for each virtual host. Here is my
> > config file, with only one host so far:
> > 
> > error_log  logs/main_error.log;
> > 
> > events {
> >    worker_connections  1024;
> > }
> > 
> > http {
> >    error_log logs/http_error.log;
> >    server {
> >        server_name myname.org;
> >        access_log logs/the_org.access;
> >        error_log logs/the_org.error;
> >    }
> > }
> > 
> > Here is the problem: when the server receives a request for
> > http://myname.org/nonexistent.file, the request shows up in the access
> > log (the_org.access), but all 3 error logs remain blank. The error
> > only shows up in the main_error.log if I comment the
> > "error_log logs/http_error.log;"
> > and
> > "error_log logs/the_org.error;"
> > lines.
> 
> The problem is that nginx sets reasonable logging level 
> automatically only for global error_log (it's defaults to error if 
> not defined).  For others it's defaults to stderr, i.e. nothing is 
> logged.  Solution is simple - explicitly specify logging level:
> 
> error_log logs/main_error.log error;
> 
> events {
>     worker_connections  1024;
> }
> 
> http {
>     error_log logs/http_error.log error;
>     server {
>         server_name myname.org;
>         access_log logs/the_org.access;
>         error_log logs/the_org.error error;
>     }
> }
> 
> Since there is no official documentation for error_log directive 
> at all - this probably can't be considered as a bug.  It's up to 
> Igor either fix it or document as is.

The attached patch should fix the bug.


-- 
Igor Sysoev
http://sysoev.ru/en/
-------------- next part --------------
Index: src/core/ngx_log.c
===================================================================
--- src/core/ngx_log.c	(revision 1760)
+++ src/core/ngx_log.c	(working copy)
@@ -302,7 +302,10 @@
         }
     }
 
-    if (log->log_level == NGX_LOG_DEBUG) {
+    if (log->log_level == 0) {
+        log->log_level = NGX_LOG_ERR;
+
+    } else if (log->log_level == NGX_LOG_DEBUG) {
         log->log_level = NGX_LOG_DEBUG_ALL;
     }
 
Index: src/core/ngx_cycle.c
===================================================================
--- src/core/ngx_cycle.c	(revision 1760)
+++ src/core/ngx_cycle.c	(working copy)
@@ -394,11 +394,7 @@
     cycle->log = cycle->new_log;
     pool->log = cycle->new_log;
 
-    if (cycle->log->log_level == 0) {
-        cycle->log->log_level = NGX_LOG_ERR;
-    }
 
-
     /* create shared memory */
 
     part = &cycle->shared_memory.part;


More information about the nginx mailing list