Gokul Muralidharan
Gokul Muralidharan

Reputation: 161

Logging specific requests in a separate file

I would like to log requests coming for a particular file, say collect.gif into a separate log file using .htaccess, it this is achievable ?

E.g http://www.domain.com/collect.gif?user=1&page=sample must alone get logged into a file collect.log

Upvotes: 2

Views: 1489

Answers (1)

Sean Bright
Sean Bright

Reputation: 120714

This is covered almost exactly in the CustomLog section of the Apache documentation. Reproducing the relevant section here:

SetEnvIf Request_URI \.gif$ gif-image
CustomLog gif-requests.log common env=gif-image
CustomLog nongif-requests.log common env=!gif-image

So for your situation, you would just change the SetEnvIf conditional to match the request you are after:

SetEnvIf Request_URI collect\.gif$ gif-image
CustomLog gif-requests.log common env=gif-image
CustomLog nongif-requests.log common env=!gif-image

Upvotes: 2

Related Questions