aoline.com simple non technical information

Stop logging images in Apache log files

Web server log files contain mostly useful information and if your website is busy you might find that your logs are full of entries you don't really need.

Here is a simple technique to reduce your server log file sizes and make them easier to read.

Simply stop logging requests for information you don't really need.

Open up your apache2.conf file:

pico /etc/apache2/apache2.conf

Look for the section containing your log file entries:

LogFormat "%h %l %u %t etc...

Right after add these lines

SetEnvIf Request_URI \.gif no-log
SetEnvIf Request_URI \.jpg no-log
SetEnvIf Request_URI \.jpeg no-log
SetEnvIf Request_URI \.css no-log
SetEnvIf Request_URI \.js no-log

You can add as many of these env entries you please. If you want to prevent logging of a particular folder relative to the / root folder, eg for your CMS or similar simply add a line like this:

SetEnvIf Request_URI ^/subfolder/ no-log

Or if you want to protect all folder contents with the same name no matter where in the root path they are then use this:

SetEnvIf Request_URI "\/subfolder\/*" no-log

Now look for the <VirtualHost *> section for the website you want to stop the logging on these items and add the env=!no-log to the end of the existing CustomLog entry as follows:

CustomLog /var/www/sitename.com/logs/access_log common env=!no-log

Now save and exit and restart Apache as follows:

/etc/init.d/apache2 reload

You can test this by browsing a few pages on your site and then viewing your access log file, you should see the recent entries are a lot cleaner.