Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache 404 error Log to a different log file

Tags:

logging

apache

We want to separate 404 not found errors into a different log file. Now our log file (apache) that writes this errors is in "access.log" file.

We want to have 404 not found errors for example in notfound.log

I did a test writting in apache2.conf:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" notfound

and in VirtualHost of apache sites-available:

CustomLog ${APACHE_LOG_DIR}/not-found.log notfound expr=.*404.*

But I got "error in condition clause"

I tried to set a env variable in VirtualHost too:

SetEnvIf expr .*404.* httpcode

And call it in CustomLog expr but didn't work. Somebody can help us, please?

Thank you.

like image 260
Santi Avatar asked Jan 23 '14 17:01

Santi


People also ask

Where are 404 errors logged?

A 404 error is not strictly a server error. It's an expected HTTP response, so it naturally appears in the access log (as you have stated), not in the error log. The "404" is the HTTP response code, not a server error code.

What is the difference between Apache's access log and the error log?

Basically, the difference is in the names. Access logs is everything, so everyone, every time somebody or something has accessed the website. Error logs just record the same information but only for error pages.

What are the different Apache Web server log files?

In Linux, Apache commonly writes logs to the /var/log/apache2 or /var/log/httpd directories depending on your OS and Virtual Host overrides. You can also define a LogFormat string after the filename, which will only apply the format string to this file.


1 Answers

Your approach could work if you install the custom Apache module SetEnvIfPlus. This should allow you to set an environment variable using the ResponseSetEnvIfPlus directive and then use that envirionment variable to force a custom log file.

like image 192
rmeakins Avatar answered Sep 24 '22 15:09

rmeakins