Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#717 closed defect (invalid)

Conditional logging does not work as expected - negated conditions log to more than one file

Reported by: Mercedes Coyle Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.7.x
Keywords: conditional logging Cc:
uname -a: Linux [host] 3.2.0-31-virtual #50-Ubuntu SMP Fri Sep 7 16:36:36 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.7.9
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/var/run/ --user=www-data --group=nginx --with-debug --with-file-aio --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx-1.7.9/body --http-fastcgi-temp-path=/var/lib/nginx-1.7.9/fastcgi --http-proxy-temp-path=/var/lib/nginx-1.7.9/proxy --http-scgi-temp-path=/var/lib/nginx-1.7.9/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx-1.7.9/uwsgi --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_spdy_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/usr/local/src/nginx-1.7.9/modules/nginx-dav-ext --add-module=/usr/local/src/nginx-1.7.9/modules/nginx-echo-0.57 --add-module=/usr/local/src/nginx-1.7.9/modules/nginx-geoip-0.2 --add-module=/usr/local/src/nginx-1.7.9/modules/nginx-http-auth-pam-1.3 --add-module=/usr/local/src/nginx-1.7.9/modules/nginx-upstream-fair --with-cc-opt='-Wno-error -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed'


I am trying to setup conditional logging so that POST requests with a debug header are routed to a separate logfile. If the debug header is not set, or it is set to false, then $debug value will be 0. If it is set to true, $debug value will be 1. The request should be logged to one of two files depending on the value of $debug, using a conditional (if=$debug and if=!$debug).

map $http_debug $debug {

default 0;

“false" 0;
"true" 1;


location = /events {

if ($request_method = POST) {

access_log /path/to/logfile/access_post.log post_events_format if=!$debug;
access_log /path/to/logfile/access_post_header.log events_header_format if=$debug;


I would expect the above conditional to log a $debug=0 request to access_post.log, and a $debug=1 request to access_post_header.log. In actuality, the $debug=0 requests are logged to access_post.log, and $debug=1 requests are logged to both access_post_header.log and access_post.log.

Change History (2)

comment:1 by Valentin V. Bartenev, 9 years ago

Resolution: invalid
Status: newclosed

The ! symbol has no special meaning. A quote from the documentation:

A request will not be logged if the condition evaluates to “0” or an empty string.

So the !$debug condition always evaluates to a non-empty string, since it contains at least one character and it's not 0.

Last edited 9 years ago by Valentin V. Bartenev (previous) (diff)

comment:2 by Mercedes Coyle, 9 years ago

Ah, thanks for clearing that up. I can work around it.

Note: See TracTickets for help on using tickets.