3 # Copyright 2000-2004 Apache Software Foundation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # This script will take a combined Web server access
19 # log file and break its contents into separate files.
20 # It assumes that the first field of each line is the
21 # virtual host identity (put there by "%v"), and that
22 # the logfiles should be named that+".log" in the current
25 # The combined log file is read from stdin. Records read
26 # will be appended to any existing log files.
30 while ($log_line = <STDIN>) {
32 # Get the first token from the log record; it's the
33 # identity of the virtual host to which the record
36 ($vhost) = split (/\s/, $log_line);
38 # Normalize the virtual host name to all lowercase.
39 # If it's blank, the request was handled by the default
40 # server, so supply a default name. This shouldn't
41 # happen, but caution rocks.
43 $vhost = lc ($vhost) or "access";
45 # if the vhost contains a "/" or "\", it is illegal so just use
46 # the default log to avoid any security issues due if it is interprted
47 # as a directory separator.
48 if ($vhost =~ m#[/\\]#) { $vhost = "access" }
50 # If the log file for this virtual host isn't opened
53 if (! $is_open{$vhost}) {
54 open $vhost, ">>${vhost}.log"
55 or die ("Can't open ${vhost}.log");
59 # Strip off the first token (which may be null in the
60 # case of the default server), and write the edited
61 # record to the current log file.
63 $log_line =~ s/^\S*\s+//;
64 printf $vhost "%s", $log_line;