NAME Apache::Log::Parser - Parser for Apache Log (common, combined, and any other custom styles by LogFormat). SYNOPSIS my $parser = Apache::Log::Parser->new( fast => 1 ); my $log = $parser->parse($logline); $log->{rhost}; #=> remote host $log->{agent}; #=> user agent DESCRIPTION Apache::Log::Parser is a parser module for Apache logs, accepts 'common', 'combined', and any other custom style. It works relatively fast, and process quoted double-quotation properly. Once instanciate a parser, it can parse all of types specified with one method 'parse'. USAGE This module requires a option 'fast' or 'strict' with instanciate. 'fast' parser works relatively fast. It can process only 'common', 'combined' and custom styles with compatibility with 'common', and cannot work with backslash-quoted double-quotes in fields. # Default, for both of 'combined' and 'common' my $parser = Apache::Log::Parser->new( fast => 1 ); my $log1 = $parser->parse(<{rhost}, $log1->{date}, $log1->{path}, $log1->{refer}, $log1->{agent}, ... my $log2 = $parser->parse(<s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%v\" \"%{cookie}n\" %D" my $c_parser = Apache::Log::Parser->new( fast => [[qw(refer agent vhost usertrack request_duration)], 'combined', 'common'] ); my $log3 = $c_parser->parse(<{agent}, $log3->{vhost}, $log3->{usertrack}, ... 'strict' parser works relatively slow. It can process any style format logs, with specification about separator, and checker for perfection. It can also process backslash-quoted double-quotes properly. # 'strict' parser is available for log formats without compatibility for 'common', like 'vhost_common' ("%v %h %l %u %t \"%r\" %>s %b") my @customized_fields = qw( rhost logname user datetime request status bytes refer agent vhost usertrack request_duration ); my $strict_parser = Apache::Log::Parser->new( strict => [ ["\t", \@customized_fields, sub{my $x=shift;defined($x->{vhost}) and defined($x->{usertrack}) }], # TABs as separator [" ", \@customized_fields, sub{my $x=shift;defined($x->{vhost}) and defined($x->{usertrack}) }], 'combined', 'common', 'vhost_common', ]); my $log4 = $strict_parser->parse(<{agent} #=> 'Any "Quoted" User-Agent' my $log5 = $strict_parser->parse(< SEE ALSO