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] 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?


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).

| improve this answer | |
  • Cool. Sorry, I missed the fact you were after error logging, not access. – LukeR Jul 9 '09 at 8:54

You can do conditional logging using mod_log_config

This will allow you to use environment variables.

Example here for not logging image requests.

| improve this answer | |
  • Thank you for answer. I don't mind having these files in access.log. What I want is to get rid of log entries for missing files in ErrorLog. Unfortunately ErrorLog doesn't support conditional logging using environment variables :-( – Peter Štibraný Jul 7 '09 at 5:01

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?

| improve this answer | |
  • I am still interested in missing files ... except those few files I know are missing and get lot of hits everyday. – Peter Štibraný Jul 11 '09 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.