
Logfiles
|
141
All those % things stand for Apache configuration variables; for example, %h means
hostname. The combined format is just the common format plus the referer and the
user agent (browser). Unfortunately, neither format includes the name of the virtual
host (a
%v variable), which you need to split the log by host. Therefore, if you want to
do this you’ll need to define a new logfile type.
Rather than getting your fingerprints all over the master Apache configuration file,
continue to make your changes to the site file we’ve been using thus far (/etc/
apache2/sites-enabled/000-default). Put these lines above any of your
VirtualHost
directives:
# Define a new virtual host common log format:
LogFormat "%v %h %l %u %t \"%r\" %s %b" vcommon
Splitting Logs with vlogger
You may be wondering whether to split lines of logging information into separate
files as Apache is being accessed, or to split the access file once a day with a utility
such as Apache’s split-logfile. We prefer the first option, because it diverts the lines
into the proper access logs immediately, and we don’t need to write cron jobs. A
good splitter is the vlogger program. Apache allows you to pipe the log through some
external program, which is just what we want. Add this right below the
LogFormat
line you just entered:
# Split log on the fly into virtual host directories
# under /var/log/apache2:
CustomLog "| /usr/sbin/vlogger -s ...