LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache Don't Log 404 Errors (https://www.linuxquestions.org/questions/linux-server-73/apache-dont-log-404-errors-789104/)

fukawi2 02-14-2010 06:17 PM

Apache Don't Log 404 Errors
 
I have a MediaWiki installation, which returns a 404 error to the client when they request a page that doesn't exist yet. This is correct/desired behaviour, however it is also expected behaviour, so I don't want to log these errors to the log file. Examples of these logs are:

Code:

/index.php/ArchServer_Wiki:Current_events: 2 Time(s)
/index.php/ArchServer_Wiki:General_disclaimer: 1 Time(s)

These "false positives" make it difficult to find genuine 404 errors that need attention when reviewing the logs.

I can use SetEnvIf to create a rule like:
Code:

SetEnvIf Request_URI "^/index\.php/.*$" dontlog
CustomLog "/var/log/httpd/wiki-access_log" combined env=!dontlog

But this will prevent ALL logging, which then screws up my statistics for pages that do exist. I can't see anyway to test the HTTP Status Code using SetEnvIf.

j-ray 02-15-2010 02:42 AM

http://helicontech.blogspot.com/2009...abilities.html


Per status code differentiation
We all like HTTP status 200. It means 'OK' and that's why we're not interested in loging it. Most common situation is when we are looking for some psecific status code in the logs. With mod_log_config you may create separate logs for every needed status. Please look at this configuration:

CustomLog ok.log "%200t %200a,%200{User-Agent}i %200U%200q %200s"
CustomLog redirections.log "%301t %301a,%301{User-Agent}i %301U%301q %301s"
CustomLog not_found.log "%404t %404a,%404{User-Agent}i %404U%404q %404s"
CustomLog server_error.log "%500t %500a,%500{User-Agent}i %500U%500q %500s"

Hope this helps...

fukawi2 02-15-2010 02:51 AM

Hmmm, a custom setenvif module... That could be a solution. Thanks, I hadn't seen that in my Googling :)

fukawi2 02-17-2010 12:04 AM

OK, well that software from a mod_rewrite clone for IIS, so that was a no go.... But I have found a solution! :D

Code:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php/(.+)
RewriteCond %{REQUEST_URI} -U
RewriteRule ^(.*)$ - [env=dontlog:true]
CustomLog "/var/log/httpd/access_log" combined env=!dontlog



All times are GMT -5. The time now is 01:12 PM.