log-splitting within a virtual-host in apache

If like me, you see nginx as a flash in the pan newcomer (released in 2004) and mod_balancer as entirely everything one would require in a load balancer.

Then you might well have some Apache config files that have grown over the years into vast monstrosities of Alias and ProxyPass, then no-one understands what they all do.



So if you have a virtual host like so;



ServerName mystupidwebsite.com
CustomLog logs/access_log

ErrorLog logs/error_log

Alias /somethign /var/somewhere/else
ProxyPass /SomeMiniSite http://my.tomcat.server.local:8080/SomeMiniSite


You might find you want to split the logging for some sub-URI path like so;

/SomeMiniSite -> /var/log/httpd/someotherlogformat.log


One way to achieve that is via setting an environment variable based on the required sub-path like so, and using that to select the CustomLog directive


...

SetEnvIf Request_URI ^/SomeMiniSite SomeMiniSite
CustomLog logs/myminisite-access.log common env=SomeMiniSite



(you can switch the log format for the other CustomLog location


Alternatives

Apache supports piping the CustomLog like so;

CustomLog "| /usr/local/sbin/log_spltter" combined


Also there appear to be some virtual directives with the  mass virtual hosting examples here;
http://httpd.apache.org/docs/2.2/vhosts/mass.html

with some ideas for log splitting based on a custom log format called vcommon



Notes
I've not consider what effect this would have on performance, so it would be worth keeping an eye on which is the most resource sucking.

No comments:

Post a Comment

Don't be nasty. Being rude is fine.