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.
You just specify
ErrorLog
andCustomLog
within eachVirtualHost
directive. With that in mind, you would not be able to useServerAlias
and have separate log files for each host via normal performance without specifying separateVirtualHost
.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 thepostrotate
orpreprotate
sections.Apache 2.2 Piped Logging
You should be able to use apache environment variables to get this working: