I have many virtual hosts set up on a web server, each one having its own error and access log. The relevant lines of httpd.conf
are something like this:
ErrorLog /var/log/httpd-error.log
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /var/log/httpd-access.log combined
NameVirtualHost *:80
<VirtualHost *:80>
ServerName myhost.com
ServerAlias www.myhost.com
DocumentRoot /var/www/myhost.com/htdocs
ErrorLog /var/www/myhost.com/log/error.log
CustomLog /var/www/myhost.com/log/access.log combined
</VirtualHost>
# ... many more VirtualHosts
Currently, I'm getting some random errors in /var/log/httpd-error.log, but I'm getting nothing in /var/log/httpd-access.log. Is it possible to have ALL accesses and errors duplicated to a shared logfile? Is it possible to do this without adding new entries to every single VirtualHost?
Best Answer
See http://httpd.apache.org/docs/2.2/logs.html#virtualhost
In other words, if you place Logging directives within a VirtualHost section, it will override the Logging directives within the main server configuration. If you want to log to a single logfile, then remove the log configuration from your VirtualHost sections.
For simplicity, I prefer to log all Access data to a single logfile. Later, you can process the logs and split the logfiles into logfiles for the Virtual Hosts. Also, writing to a single logfile is a more efficient use of computer resources then writing to 30 logfiles at once. Just make sure your LogFormat includes the '%v', which will log the name of the Virtual Host.
You can log all errors and access to a shared logfile, but the logfile is ugly. First, send the Apache log data to syslog, and then use syslog to send to a local file or a remote log server.
And then in /etc/syslog.conf