Tuesday, June 1, 2010

Logging in Apache - don't log favicon.ico

Apache logs a lot of info, but it can be configured.

Here is a brief description of what i've done to apache config, so that it would not log some hits, for example "favicon.ico", here it goes:

First i altered /etc/apache2/apache2.conf (other systems can be httpd.conf)

I don't want to log agents...
In these lines:
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined

LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined


I modified to look like this:
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O" vhost_combined

A lot less info about agent's ;)

Now for the sites, in the file /etc/apache2/sites-available/default i added this:
SetEnvIf Request_URI "^/favicon\.ico$" dontlog

then on the line that has the CustomLog entry:
CustomLog /var/log/apache2/access.log combined env=!dontlog

After this the favicon.ico continues to log in the error.log, so i created a zero size file in /var/www/
# cat /dev/null > favicon.ico

I know it's not the best for debugging but i like it better like this, i think it's better for reading ;)
.

No comments: