Conditional Log filtering for your apache

At my website I found that there were lots of log entry at my access_log for GIF images. I wanted to find a way so that there will be no entry at my access_log for GIF images. I found the way, and here is how you need to filter your log entry for GIF images.

SetEnvIf Request_URI \.GIF$ no-log
CustomLog log/access.log combined env =! no-log


This will help you to prevent writing any entry at your log file. If you want to add more file types at your filtering condition, you can use them using pipe(|). For example below.

SetEnvIf Request_URI "\.(PNG|png|gif|GIF)$" no-log
CustomLog log/access.log combined env =! no-log


But for anything, make sure that you have setenvif module is loaded. To check this you can use either httpd -M or apache2 -M depending upon your system.

Hope this little information will help you to setup custom logging for your apache.

Comments