Avoid logging of certain missing files into the Apache2 error log

I'd like to avoid logging some missing files (that gives a 404) into the Apache2 error log.

I want to do this on an Eclipse update site for my plugin. Problem is that the Eclipse P2 code tries to access its metadata files like content.xml, content.jar, digest.zip and a few others, which are not available on my site. When P2 finds this out, it finally reaches for site.xml, which I provide. All in all, everything works fine ... but I have tons of lines like:

[Mon Jul 06 21:46:46 2009] [error] [client 195.91.79.90] File does not exist: ...htdocs/stable/content.jar

in my error.log file, which doesn't help me very much.

One solution that comes to my mind is to let Apache log through grep (via pipe-logging), but I am looking for a better solution.

I was thinking about tagging these requests with SetEnvIf directive, and skipping error log for tagged requests, but the ErrorLog directive doesn't support that.

Any other ideas?


Solution 1:

I found a solution that works for me. I added these lines to .htaccess:

# Don't log missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(artifacts\.jar|content\.xml|content\.jar)$ - [R=404,L]

It uses mod_rewrite. R=404 says to send 404 Not Found status code when client accesses any of mentioned files.

RewriteCode is there to make sure that file indeed doesn't exist. If I ever put one of those files into the directory, it will be served as usual.

This works great: mentioned files are no longer logged into error.log (that was my goal), but are still logged in access log (with 404 status).

Solution 2:

You can do conditional logging using mod_log_config

This will allow you to use environment variables.

Example here for not logging image requests.

Solution 3:

Wouldn't it have been easier to increase your LogLevel higher than error to warn or crit? Or do you have a reason to keep it lower?