Apache access logs and multiple domains to same place

Dominic Mitchell dom at happygiraffe.net
Tue Nov 2 12:48:14 GMT 2004


--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Nov 02, 2004 at 09:18:43AM +0000, Matthew Seaman wrote:
> Note that the default and the pre-canned custom access.log formats in
> httpd.conf don't contain any record of which virtual host a request
> was made to.  You need to add a '%v' to your log format to get that
> (see http://httpd.apache.org/docs/mod/mod_log_config.html#formats) --
> but that means your log analysis software will need to be similarly
> customised.

What I do is stick %v on to the front of the line, and then split the
logs into different files based on that first field.  Attached is the
very small perl script I use to do this.  That leaves you with a number
of log files which can then be processed normally.

-Dom

--Nq2Wo0NMKNjxTN9z
Content-Type: application/x-perl
Content-Disposition: attachment; filename="splitlogs.pl"
Content-Transfer-Encoding: quoted-printable

#!/usr/bin/perl -w=0A#=0A# @(#) $Id: splitlogs.pl 833 2004-11-02 12:47:00Z =
dom $=0A#=0A=0Ause strict;=0A=0Awhile (<>) {=0A    my ($host, $line) =3D sp=
lit ' ', $_, 2;=0A    my $fh =3D get_fh( $host );=0A    print $fh $line;=0A=
}=0A=0Amy %fh_cache;=0Asub get_fh {=0A    my $host =3D shift;=0A    return =
$fh_cache{ $host } if $fh_cache{ $host };=0A    my $fn =3D "${host}_access.=
log";=0A    open( my $fh, '>', $fn )=0A      or die "$0: open($fn): $!\n";=
=0A    return $fh_cache{ $host } =3D $fh;=0A}=0A
--Nq2Wo0NMKNjxTN9z--




More information about the Ukfreebsd mailing list