|
Apache::LogRegex - Parse a line from an Apache logfile into a hash |
Apache::LogRegex - Parse a line from an Apache logfile into a hash
This document refers to version 1.4 of Apache::LogRegex, released October 21st 2006
use Apache::LogRegex;
my $lr;
eval { $lr = Apache::LogRegex->new($log_format) };
die "Unable to parse log line: $@" if ($@);
my %data;
while ( my $line_from_logfile = <> ) {
eval { %data = $lr->parse($line_from_logfile); };
if (%data) {
# We have data to process
} else {
# We could not parse this line
}
}
Designed as a simple class to parse Apache log files. It will construct a regex that will parse the given log file format and can then parse lines from the log file line by line returning a hash of each line.
The field names of the hash are derived from the log file format. Thus if the format is '%a %t \``%r\'' %s %b %T \``%{Referer}i\'' ...' then the keys of the hash will be %a, %t, %r, %s, %b, %T and %{Referer}i.
Should these key names be unusable, as I guess they probably are, then subclass
and provide an override rename_this_name() method that can rename the keys
before they are added in the array of field names.
names()regex()
Perl 5
The only problem I can foresee is the various custom time formats but providing that they are encased in '[' and ']' all should be fine.
new() takes 1 argumentnew() argument 1 (FORMAT) is undefinedparse() takes 1 argumentparse() argument 1 (LINE) is undefinednames() takes no argumentregex() takes no argument
None so far
None
mod_log_config for a description of the Apache format commands
Peter Hickman (peterhi@ntlworld.com)
Copyright (c) 2004, Peter Hickman. All rights reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
Apache::LogRegex - Parse a line from an Apache logfile into a hash |