7

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?

3 Answers 3

8

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

1
  • Cool. Sorry, I missed the fact you were after error logging, not access.
    – LukeR
    Jul 9, 2009 at 8:54
3

You can do conditional logging using mod_log_config

This will allow you to use environment variables.

Example here for not logging image requests.

1
  • 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 :-( Jul 7, 2009 at 5:01
1

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?

1
  • I am still interested in missing files ... except those few files I know are missing and get lot of hits everyday. Jul 11, 2009 at 12:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .