3.11. Maintaining Separate Logs for Each Virtual Host
Problem
You want to have separate activity logs for each of your virtual hosts, but you don’t want to have all the open files that multiple CustomLog directives would use.
Solution
Use the split-logfile
program that comes with Apache. To split logfiles after they’ve been
rolled over (replace /path/to/ServerRoot
with the correct path):
#cd/path/to/ServerRoot#mv logs/access_log logs/access_log.old#bin/apachectl graceful[wait for old logfile to be completely closed] #cd logs#../bin/split-logfile < access_log.old
To split records to the appropriate files as they’re written, add this line to your httpd.conf file:
CustomLog "| /path/to/split-logfile /usr/local/Apache/logs" combinedDiscussion
In order for split-logfile to work, the
logging format you’re using must begin with “%v” (note the blank after the v). This inserts the name of the virtual
host at the beginning of each log entry;
split-logfile will use this to figure out to
which file the entry should be written. The hostname will be removed
from the record before it gets written.
There are two ways to split your access logfile: after it’s been written, closed, and rolled over, or as the entries are actually being recorded. To split a closed logfile, just feed it into the split-logfile script. To split the entries into separate files as they’re actually being written, modify your configuration to pipe the log messages directly to the script.
Each method has advantages and disadvantages. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access