--------------------- PatchSet 11188 Date: 2007/01/24 06:50:35 Author: adrian Branch: HEAD Tag: (none) Log: This is a simple Perl library which facilitates parsing access logfile entries. Members: scripts/Squid/ParseLog.pm:INITIAL->1.1 --- /dev/null Wed Jan 24 06:52:22 2007 +++ squid/scripts/Squid/ParseLog.pm Wed Jan 24 06:52:22 2007 @@ -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;