Jamie
Jamie

Reputation: 7421

How can I generate seperate logs for different HTML URL paths?

I'm trying to breakout the logging of my website based on directory access, so I'm seeking an elaboration to this answer (or this answer too): In which file do place the suggested answer?

I put the following in my /etc/apache2/apache2.conf (actually via an Include my-logging.conf):

SetEnvIf Request_URI "^/download/.+$" download_access
CustomLog /home/jamie/apache-logs/download.log common env=download_access

The directory /home/jamie/apache-logs/ and the files therein are universally writable, but when I access the resource via my browser (http://download/index.html) the main access log (/var/log/access.log) is updated but not the log I was hoping would be: /home/jamie/apache-logs/download.log remains untouched.

I'm reasonably certain mod_setenvif is already enabled:

$ sudo a2enmod setenvif
Module setenvif already enabled

How can I make this work?

Upvotes: 1

Views: 2158

Answers (2)

Kasapo
Kasapo

Reputation: 5374

EDIT:

No, it was the regex. Head slap is right.


Have you looked to see if there are places in /etc/apache2/apache2.conf or in the other included sites files (maybe /etc/apache2/sites-enabled/foo.conf or /etc/apache2/conf/foo.conf or something... I use a different distro) that have different CustomLog definitions?

There is more than likely something over-riding your statement. The best place to put the CustomLog directive is in the <VirtualHost> stanza that defines your site. That way, the directive will have the highest precedence so it will override the server-wide settings. What I think is happening is that your definition is setting a default for the server, but a more specific customlog statement is inside a VirtualHost and overriding it.

Upvotes: 1

Jamie
Jamie

Reputation: 7421

Head Slap!

Regular expression error:

SetEnvIf Request_URI "^/download/.+$" download_access

should be:

SetEnvIf Request_URI "^/download/.*$" download_access

Note the * versus the +.

Upvotes: 2

Related Questions