Conditional Logging in ApacheBy Blane Warrene
Often we find entries in our web logs which we seek to supress or block based on the fact that these entries may be skewing true statistics.
Most web log analysis software offers exclusion filters to block numerous types of entries. However, this can also be done natively in Apache.
For example, perhaps we would like to exclude our own IP address as well as requests for the favicon.ico from the logs.
(You will need to modify the IP address to a real one for this to work – i.e. either your machine IP address if using static IP or that of your proxy server/router if proxying Internet access from your local network.)
# Prevent entries from my host address
SetEnvIf Remote_Addr "10.0.0.1" dontlog
# Prevent entries for the favicon.ico file
SetEnvIf Request_URI "^/favicon.ico$" dontlog
# Log what remains
CustomLog logs/web.log combined env=!dontlog
Additionally, you could additionally prevent requests for the robots.txt file from being logged as well.
# Prevent entries for robots.txt
SetEnvIf Request_URI "^/robots.txt$" dontlog
NOTE: Remember to change the log type to that which you prefer, i.e. I use the combined log format instead of common. See your httpd.conf file for your current log format type.