Different Apache log file for each subdomain

apache-2.2logging

Is it possible to configure Apache to use a different log file for each subdomain, even if all of the subdomains are within the same VirtualHost container?

So, I have only one VirtualHost:

<VirtualHost *:80>
  ServerName example.com
  ServerAlias test1.example.com test2.example.com test3.example.com
</VirtualHost>

And I want to end up with the following log files:

/var/log/httpd-access_test1.log
/var/log/httpd-access_test2.log
/var/log/httpd-access_test3.log

I know I can probably do this with a custom log format and split-logs, but I was wondering if there's a way to just have Apache do it for me.

Best Answer

You just specify ErrorLog and CustomLog within each VirtualHost directive. With that in mind, you would not be able to use ServerAlias and have separate log files for each host via normal performance without specifying separate VirtualHost.

However, you could pipe the log through a script, and have the script make the separate files. Look at the piped logging documentation.

You could also use a post processing script, such as utilizing grep to parse out the logs. A post processing script could be specified in the nightly logrotate under the postrotate or preprotate sections.

Apache 2.2 Piped Logging

Related Topic