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