From: Amos Jeffries Date: Sun, 12 Jul 2009 03:31:37 +0000 (+1200) Subject: Author: Adrian Chadd X-Git-Tag: SQUID_3_2_0_1~892 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b8ace12eeb5d5e1108b51c6afaa7b0573c0658b;p=thirdparty%2Fsquid.git Author: Adrian Chadd This is a simple Perl library which facilitates parsing access logfile entries. --- diff --git a/scripts/Squid/ParseLog.pm b/scripts/Squid/ParseLog.pm new file mode 100644 index 0000000000..fe0b312849 --- /dev/null +++ b/scripts/Squid/ParseLog.pm @@ -0,0 +1,43 @@ +#!/usr/bin/perl -w + +# +# This is a simple module which takes in a Squid format logfile line and breaks it up into +# a perl hash. +# +# I'm not going to pretend this is 100% accurate just yet but its a start. +# I'm hoping that by placing it into the public domain it (and the other stuff +# I sneak in here) will be debugged and improved by others. +# +# Adrian Chadd +# +# $Id: ParseLog.pm,v 1.1 2007/01/24 06:50:35 adrian Exp $ +# + +use strict; + +package Squid::ParseLog; + +sub parse($) { + my ($line) = @_; + my (%t); + chomp $line; + + $line =~ m/^(.*?) (\d+?) (.*?) (.*?)\/(\d+?) (\d+?) (.*?) (.*?) (.*?) (.*?)\/(.*?) (.*)$/; + + $t{"timestamp"} = $1; + $t{"reqtime"} = $2; + $t{"clientip"} = $3; + $t{"code"} = $4; + $t{"httpcode"} = $5; + $t{"size"} = $6; + $t{"method"} = $7; + $t{"url"} = $8; + $t{"username"} = $9; + $t{"fwdcode"} = $10; + $t{"fwdip"} = $11; + $t{"mime"} = $12; + + return \%t; +} + +1;