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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With