Image-Free Apache Access Log

Apache logs can get very large very fast. Even with a relatively limited user base, the access log becomes unwieldy. Fortunately, you can easily filter what goes into the log. For example, it is seldom useful to have image or javascript requests in the log.

To eliminate unwanted requests from the log, find the relevant apache configuration file (as you know, this varies by Unix platform; here I am demonstrating how to accomplish this in Ubuntu).

cd /etc/apache2/sites-available
sudo vi default

You want to set an environment variable based on the type of URI request and then have the custom log ignore those requests.

<VirtualHost *:80>

        ...

        SetEnvIf Request_URI \.gif nolog
        SetEnvIf Request_URI \.jpg nolog
        SetEnvIf Request_URI \.png nolog
        SetEnvIf Request_URI \.js nolog
        SetEnvIf Request_URI \.css nolog

        CustomLog ${APACHE_LOG_DIR}/access.log combined env=!nolog

</VirtualHost>

As always, do an apache configuration test to make sure you haven't made a mistake, and then restart apache.

sudo apachectl configtest
sudo service apache2 restart

Your apache access log will be much cleaner now!