From 51f1e834b8f73720005ee5bbb53a66552df115ff Mon Sep 17 00:00:00 2001
From: Richard Bowen
When you wish to split your log file into its component parts (one -file per virtual host) you can use a program like the following to -accomplish this:
- -+file per virtual host) you can use the program
-#!/usr/bin/perl -# Filename: split_log -# Usage: split_log multiple_vhost_log -# Creates one log file per virtual host - -use strict; -my $file = $ARGV[0]; # Name of the log file -my %fh; # File handles - -# Read the log file, one line at a time -open LOG, $file; -foreach my $line (<LOG>) { - $line =~ s/^(.*?) //; - - # Do we already have a file handle for this vhost? - unless ($fh{$1}) { - my $handle; - open ($handle, '>' , $1 . '_split'); - $fh{$1} = $handle; - } - - # Write out the log entry - select ($fh{$1}); - print $line; -} -close LOG; - -# Close all the open file handles -foreach my $h ( keys %fh ) { - close $h; -} -
split-logfile
to accomplish
+this. You'll find this program in the support
directory
+of the Apache disribution.
+
+Run this program with the command:
+ +
+ split-logfile < /logs/multiple_vhost_log
+
This program, when run with the name of your vhost log file, will
generate one file for each virtual host that appears in your log file.
-Each file will be called hostname_split
.
hostname.log
.