3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements. See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License. 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.
34 while (my $log_line = <STDIN>) {
36 # Get the first token from the log record; it's the
37 # identity of the virtual host to which the record
40 my ($vhost) = split (/\s/, $log_line);
42 # Normalize the virtual host name to all lowercase.
43 # If it's blank, the request was handled by the default
44 # server, so supply a default name. This shouldn't
45 # happen, but caution rocks.
47 $vhost = lc ($vhost) || "access";
49 # if the vhost contains a "/" or "\", it is illegal so just use
50 # the default log to avoid any security issues due if it is interprted
51 # as a directory separator.
52 if ($vhost =~ m#[/\\]#) { $vhost = "access" }
54 # If the log file for this virtual host isn't opened
57 if (! $log_file{$vhost}) {
58 open $log_file{$vhost}, ">>${vhost}.log"
59 or die ("Can't open ${vhost}.log");
62 # Strip off the first token (which may be null in the
63 # case of the default server), and write the edited
64 # record to the current log file.
66 $log_line =~ s/^\S*\s+//;
67 print {$log_file{$vhost}} $log_line;