Create an Apache log for a particular <location>
Hi
I have an apache server setup where I have different rules using <location>. Essentially, I have a test environment "/test/" and I would like to capture the logs for activity in this location and direct it into a separate log. I know that perhaps I should have set up virtual hosts, but I wasn't aware of them at the time and the change over can not be accommodated at the moment (the change control wouldn't be agreed). I was wondering if it could be done using environment variables. At the moment I use Code:
tail -f /var/log/httpd/error_log | grep "/test/" Any suggestions would be welcome. Thanks. Mark |
Hi,
You can use SetEnvIf for this, even though I also think that a virtualhost approach would be a better solution. Anyway, use in httpd.conf (or whatever .conf file apache uses) the follwoing: Code:
SetEnvIf Request_URI "^/test/" testlog Code:
CustomLog /path/to/access_log common env=!testlog |
That is great. I had most of the first part, but not the second part.
I presume the ^ in "^/test/" is part of a regex. If so that makes it a very powerful. I will definitely look at virtual hosts the next time round. Thanks for the solution. Mark |
You're welcome.
BTW, you're right: ^ is used in a regex that matches everything that starts with the string following the ^ character Regards |
Hello
Sorry to open this up again, but having tried this I realise that CustomLog appears to be logging access logs only. However, it is the ErrorLog that I wish to redirect into separate logs. Having read further I can see that ErrorLog is non-configurable, but I was wondering if the error is part of an environment variable that I can output using CustomLog. Thanks again |
Hi,
Indeed you cannot customize error_log. Anyway if you're using a CustomLog as above (i.e. using the common format), you can filter the test.log based on the response code (penultimate field): Quote:
Regards |
All times are GMT -5. The time now is 09:22 PM. |