Conditional logging
There are some instances where we may want to log different data, based on some sort of conditional argument. For instance, if you have a beta copy of your application and are interested in gathering more information for it, we can log this data just for the beta URL. Rather than clogging up our log files with the additional information when it's not required, we can simply trigger it when required.
How to do it...
To enable, we map the ($args
) URI arguments to a $debuglogs
variable, based on if a condition is set. Here's the code:
map $args $debuglogs { default 0; debug 1; }
Like the custom log formats, this needs to be placed outside of the server
directives. Then, within the server
directive, we can make use of the variable and create additional logging:
access_log /var/log/nginx/djangodemo-debug-access.log applogs if=$debuglogs; access_log /var/log/nginx/djangodemo-access.log combined;
If we call a normal URL, it will simply log the access to the...