Recipe 3.13 Logging Errors for Virtual Hosts to Multiple Files


Unlike access logs, Apache only logs errors to a single location. You want Apache to log errors that refer to a particular virtual host to the host's error log, as well as to the global error log.


There are at least two possible ways of doing this:

  1. Use piped logging to send entries to a custom script that will copy and direct error messages to the appropriate files.

  2. Use piped logging to duplicate log entries:

    ErrorLog "| tee logfile1 | tee logfile2 > logfile3"


Unlike activity logs, Apache will log error messages only to a single location. If the error is related to a particular virtual host and this host's <VirtualHost> container includes an ErrorLog entry, the error will be logged only in this file, and it won't appear in any global error log. If the <VirtualHost> does not specify an ErrorLog directive, the error will be logged only to the global error log. (The global error log is the last ErrorLog directive encountered that isn't in a <VirtualHost> container.)

Currently, the only workaround to this is to have the necessary duplication performed by a separate process (i.e., by using piped logging to send the error messages to the process as they occur). Of the two solutions given above, the first, which involves a custom script you develop yourself, has the most flexibility. If all you want is simply duplication of entries, the second solution is simpler but requires that your platform have a tee program (Windows does not). It may also be subject to lagging messages if your tee program doesn't flush its buffers after each record it receives. This could also lead to lost messages if the pipe breaks or the system crashes.

See Also


Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: