Apache Access Log: don’t log static content

If you’re running a busy webserver on Apache, it may be interesting to prevent the access log from filling up with all the static requests on your system. You can modify the log-format so it doesn’t include all the .png, .jpg, .css, .js, … files in there.

To start, add the following into your Virtual Host config of the site where you don’t want to log static content.

SetEnvIf Request_URI "\.(txt|jpg|png|gif|ico|js|css|swf|js?.|css?.)$" StaticContent

And add the following line to the CustomLog directive where you would point to your access log.

CustomLog /var/www/site/log/access.log combined env=!StaticContent

Reload your Apache and you won’t see any static content matching the regular expression at the top to enter your logs.