Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a webserver with many (thousands) VirtualHosts. With the current configuration, Apache fills 2 files for each VirtualHost: error.log + access.log. Apache works in prefork mode and to avoid to many file descriptors opened at the same time, I would like to have a single access.log and error.log for all VirtualHosts.

A CRON task will split files for each VirtualHost once a day, so I need the VirtualHost name on each line of the *.log files. This is pretty easy for access.log:

LogFormat "%V:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
CustomLog /var/log/apache2/vhosts_access.log vhost_combined

%V gives me the VirtualHost name and that's enough for splitting files.

But I just can't find the equivalent setting for ErrorLog.

Questions:

  1. in your opinion is it relevant to try to identify each the origin of each error.log line
  2. do you know a solution?
share|improve this question

2 Answers 2

up vote 2 down vote accepted

ErrorLog directive in Apache can not be customized.

If your intention is to reduce FDs, the with a single access log, an thousands of virtualhosts, you will reduce them (FDs) by at least n*virtualhosts.

My suggestion is to keep error log for each VH and as you say, split your access log as you are already doing it.

If it is as MUST to configure a single error log, each entry in error_log has a corresponding entry in access_log, so with some perl magic you could get the job done, but I think it is not worth the effort, as it would take some time to process and it is very error prone.

share|improve this answer
    
Thank you Torian. I decided for a mix between cronolog and single log file : ErrorLog is piped to cronolog (so is CustomLog). As you say, all ErrorLog entries can be found in the CustomLog as well. So in the end I have 1 access.log and 1 error.log and only 2 FDs whatever the number of vhosts: perfect. –  plegall Oct 22 '10 at 13:47

You could use an ErrorLog directive with a pipe to a one-line bash script - i.e.

ErrorLog "| /script_location 'log destination' 'virtualhost.com'"

... to the script:

#!/bin/bash
read INCOMING_LOG && echo ${2}" - "${INCOMING_LOG} >> $1
share|improve this answer
    
If he has thousands of virtualhosts that would span a hole lot of processes, and probably lead to a major problem and that would still imply an ErrorLog directive by virtual host (nothing that sed can't fix though) –  Torian Oct 22 '10 at 11:13
1  
@Torian - I wouldn't necessarily recommend the piped script (I think the real answer if the server is disk-bound with 1000's of vhosts would be an additional server) –  danlefree Oct 22 '10 at 11:54
    
well... I don't really like the idea to have an huge number of processes running. My main goal is to get better scalability and adding new processes for each new vhost is not very compatible with scalability :-/ –  plegall Oct 22 '10 at 13:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.