Reputation: 509
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.
Upvotes: 9
Views: 4330
Reputation: 4737
You can refer to Apache CustomLog Manual. It says
The CustomLog directive is used to log requests to the server. A log format is specified, and the logging can optionally be made conditional on request characteristics using environment variables.
The first argument, which specifies the location to which the logs will be written, can take one of the following two types of values:
file A filename, relative to the ServerRoot. pipe The pipe character "|", followed by the path to a program to receive the log information on its standard input.
So you can specify a program path instead of a log file path and can handle requests by that program. You can find more about piped logs here
Upvotes: -1
Reputation: 1329
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.
Upvotes: 4