NAME
Parse::AccessLog - Parse Nginx/Apache access logs in "combined" format.
VERSION
Version 0.01
SYNOPSIS
Parses web server logs created by Apache/nginx in combined format. Assumes no knowledge of the server which creates the log entries.
Following the UNIX philosophy of "write programs that do one thing and do it well", this module does not attempt to validate any of the data/fields (e.g. match the IP address via a regex or some other method). This module assumes that the logs are already written by a web server daemon, and whether the data are "correct" or not is up to the end user. This module just parses it.
use Parse::AccessLog;
my $p = Parse::AccessLog->new;
# returns one hashref
my $log_line = q{127.0.0.1 - - [11/Jan/2013:17:31:36 -0600] "GET / HTTP/1.1" 200 612 "-" "HTTP-Tiny/0.022"};
my $rec = $p->parse($log_line);
...
# returns two hashrefs...
my @log_lines = (
q{127.0.0.1 - - [11/Jan/2013:17:31:36 -0600] "GET / HTTP/1.1" 200 612 "-" "HTTP-Tiny/0.022"},
q{127.0.0.1 - - [11/Jan/2013:17:31:38 -0600] "GET / HTTP/1.1" 200 612 "-" "HTTP-Tiny/0.022"},
);
my @recs = $p->parse( @log_lines );
...
# returns a hashref for each line in 'access.log'...
my @recs = $p->parse( '/var/log/nginx/access.log' );
METHODS
new()
Constructor, creates a Parse::AccessLog parser object. Use of new() is optional, since the parse() method can be called as a class method also.
parse()
This is the only method (other than the constructor new()), and can be called as a class method or as an object method. It Does What You Want (probably).
Accepts a scalar or a list. If a scalar, can be either one line of an access log file, or can be the full path (absolute or relative) to an access log (e.g. /var/log/apache2/access.log). If a list, expects each element to be a line from an access log file. Will return either a single hashref or a list of hashrefs with the following keys:
remote_addr
remote_user
time_local
request
status
bytes_sent
referer
user_agent
SEE ALSO
http://en.wikipedia.org/w/index.php?title=Unix_philosophy&oldid=525612531
AUTHOR
Nathan Marley, <nathan.marley at gmail.com>
BUGS
Please report any bugs through github at https://github.com/nmarley/Parse-AccessLog.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Parse::AccessLog
You can also look for information at:
MetaCPAN
GitHub
Search CPAN
LICENSE AND COPYRIGHT
Copyright 2013 Nathan Marley.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.