Skip to content

Commit f913ddf

Browse files
committed
split-logfile - from apache source code.
1 parent 85f541e commit f913ddf

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

split-logfile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This script will take a combined Web server access
2+
# log file and break its contents into separate files.
3+
# It assumes that the first field of each line is the
4+
# virtual host identity (put there by "%v"), and that
5+
# the logfiles should be named that+".log" in the current
6+
# directory.
7+
#
8+
# The combined log file is read from stdin. Records read
9+
# will be appended to any existing log files.
10+
#
11+
%is_open = ();
12+
13+
while ($log_line = <STDIN>) {
14+
#
15+
# Get the first token from the log record; it's the
16+
# identity of the virtual host to which the record
17+
# applies.
18+
#
19+
($vhost) = split (/\s/, $log_line);
20+
#
21+
# Normalize the virtual host name to all lowercase.
22+
# If it's blank, the request was handled by the default
23+
# server, so supply a default name. This shouldn't
24+
# happen, but caution rocks.
25+
#
26+
$vhost = lc ($vhost) or "access";
27+
#
28+
# if the vhost contains a "/" or "\", it is illegal so just use
29+
# the default log to avoid any security issues due if it is interprted
30+
# as a directory separator.
31+
if ($vhost =~ m#[/\\]#) { $vhost = "access" }
32+
#
33+
# If the log file for this virtual host isn't opened
34+
# yet, do it now.
35+
#
36+
if (! $is_open{$vhost}) {
37+
open $vhost, ">>${vhost}.log"
38+
or die ("Can't open ${vhost}.log");
39+
$is_open{$vhost} = 1;
40+
}
41+
#
42+
# Strip off the first token (which may be null in the
43+
# case of the default server), and write the edited
44+
# record to the current log file.
45+
#
46+
$log_line =~ s/^\S*\s+//;
47+
printf $vhost "%s", $log_line;
48+
}
49+
exit 0;

0 commit comments

Comments
 (0)