Apache-LogRegex
view release on metacpan or search on metacpan
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
Apache::LogRegex
================
*Parse a line from an Apache logfile into a hash*
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.
INSTALLATION
------------
% perl Makefile.PL
% make
% make test
% sudo make install
TEST FAILURES
lib/Apache/LogRegex.pm view on Meta::CPAN
for (my $i = 0; $i < @format_elements; $i++) {
my $element = $format_elements[$i];
my $quoted = quoted_p($element);
if ($quoted) {
$element =~ s/^\\\"//;
$element =~ s/\\\"$//;
}
push @{ $self->{_regex_fields} }, $self->rename_this_name($element);
my $group = '(\S*)';
if ($quoted) {
if ($element eq '%r' or $element =~ m/{Referer}/ or $element =~ m/{User-Agent}/) {
$group = qr/"([^"\\]*(?:\\.[^"\\]*)*)"/;
}
else {
$group = '\"([^\"]*)\"';
}
lib/Apache/LogRegex.pm view on Meta::CPAN
}
sub regex {
my ($self) = @_;
die __PACKAGE__ . '->regex() takes no argument' unless @_ == 1;
return $self->{_regex};
}
sub rename_this_name {
my ($self, $name) = @_;
return $name;
}
1;
=head1 NAME
Apache::LogRegex - Parse a line from an Apache logfile into a hash
lib/Apache/LogRegex.pm view on Meta::CPAN
A simple class to parse Apache access 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.
This module supports variable spacing between elements that are
surrounded by quotes, so if you have more than one space between those
elements in your format or in your log file, that should be OK.
=head1 SUBROUTINES/METHODS
=head2 Constructor
lib/Apache/LogRegex.pm view on Meta::CPAN
=item names()
Returns a list of field names that were extracted from the data. Such as
'%a', '%t' and '%r' from the above example.
=item regex()
Returns a copy of the regex that will be used to parse the log file.
=item rename_this_name( NAME )
Use this method to rename the keys that will be used in the returned hash.
The initial NAME is passed in and the method should return the new name.
=back
=head1 CONFIGURATION AND ENVIRONMENT
Perl 5
=head1 DIAGNOSTICS
( run in 0.339 second using v1.01-cache-2.11-cpan-131fc08a04b )