How do I configure apache to log requests in the request URL matches particular regex pattern ?
-
Please clarify because all requests are logged in access.log– Romeo NinovJan 18, 2015 at 20:14
-
@RomeoNinov, yes but I want to log only certain URL matching patterns– jmjJan 18, 2015 at 20:15
-
All you can do is to use the apache log engine. If you want to extract by pattern this is different question. And my humble advise is to keep all the logs :) Check also here for some options to customize log: httpd.apache.org/docs/2.2/mod/mod_log_config.html#customlog– Romeo NinovJan 18, 2015 at 20:19
-
I know how to grep for it, My question is specifically for enabling logging for url pattern– jmjJan 18, 2015 at 20:20
-
good pointer, let me check if this setenv works in my case– jmjJan 18, 2015 at 20:24
1 Answer
You need to use the SetEnvIf
directive and add any matching Request_URI
's to a custom log. For example:
SetEnvIf Request_URI /request/to/match$ mycustomlogfile
CustomLog mycustomlogfile.log common env=mycustomlogfile
For more specifics on how to use SetEnvIf
, check out this how to page on HowToForge.com How To Tell Apache To Not Log Certain Requests In Its Access Log (Note: Although the tutorial is about not logging certain requests in apache, it's still good information on using SetEnvIf
directive.)