1

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 Ninov Jan 18 '15 at 20:14
  • @RomeoNinov, yes but I want to log only certain URL matching patterns – Jigar Joshi Jan 18 '15 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 Ninov Jan 18 '15 at 20:19
  • I know how to grep for it, My question is specifically for enabling logging for url pattern – Jigar Joshi Jan 18 '15 at 20:20
  • good pointer, let me check if this setenv works in my case – Jigar Joshi Jan 18 '15 at 20:24
2

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.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.