Mojolicious::Plugin::AccessLog - AccessLog Plugin
Version 0.002
# Mojolicious $self->plugin(AccessLog => {log => '/var/log/mojo/access.log'}); # Mojolicious::Lite plugin AccessLog => {log => '/var/log/mojo/access.log'};
Mojolicious::Plugin::AccessLog is a plugin to easily generate an access log.
Mojolicious::Plugin::AccessLog supports the following options.
log
Log data destination.
Default: $app->log->handle, so that access log lines go to the same destination as lines created with $app->log->$method(...).
$app->log->handle
$app->log->$method(...)
This option may be set to one of the following values:
plugin AccessLog => {log => '/var/log/mojo/access.log'};
A string specifying an absolute path to the log file. If the file does not exist already, it will be created, otherwise log output will be appended to the file. The log directory must exist in every case though.
# Mojolicious::Lite plugin AccessLog => {log => 'log/access.log'};
Similar to absolute path, but relative to the application home directory.
open $fh, '>', '/var/log/mojo/access.log'; plugin AccessLog => {log => $fh}; plugin AccessLog => {log => \*STDERR};
A file handle to which log lines are printed.
$log = IO::File->new('/var/log/mojo/access.log', O_WRONLY|O_APPEND); plugin AccessLog => {log => $log}; $log = Log::Dispatch->new(...); plugin AccessLog => {log => $log};
An object, that implements either a print method (like IO::Handle based classes) or an info method (i.e. Log::Dispatch or Log::Log4perl).
print
info
$log = Log::Dispatch->new(...); plugin AccessLog => { log => sub { $log->log(level => 'debug', message => @_) } };
A code reference. The provided subroutine will be called for every log line, that it gets as a single argument.
format
A string to specify the format of each line of log output.
Default: "common" (see below).
This plugin implements a subset of Apache's LogFormat.
A percent sign.
Remote IP-address.
Local IP-address.
Size of response in bytes, excluding HTTP headers. In CLF format, i.e. a '-' rather than a 0 when no bytes are sent.
Size of response in bytes, excluding HTTP headers.
The time taken to serve the request, in microseconds.
Remote host. See "hostname_lookups" below.
The request protocol.
The remote logname, not implemented: currently always '-'.
The request method.
The port of the server serving the request.
The process ID of the child that serviced the request.
First line of request: Request method, request URL and request protocol. Synthesized from other fields, so it may not be the request verbatim.
The HTTP status code of the response.
Time the request was received (standard english format).
Custom field for handling times in subclasses.
Remote user, or '-'.
The URL path requested, not including any query string.
The name of the server serving the request.
In addition, custom values can be referenced, using %{name}, with one of the mandatory modifier flags i, o, t, C or e:
%{name}
i
o
t
C
e
The contents of request header RequestHeaderName.
RequestHeaderName
The contents of response header ResponseHeaderName.
ResponseHeaderName
The time, in the form given by Format, which should be in strftime(3) format.
Format
The contents of cookie CookieName in the request sent to the server.
CookieName
The contents of environment variable VariableName.
VariableName
For mostly historical reasons template names "common" or "combined" can also be used (note, that these contain the unsupported %l directive):
%l
%h %l %u %t "%r" %>s %b
%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"
hostname_lookups
Enable reverse DNS hostname lookup if true. Keep in mind, that this adds latency to every request, if %h is part of the log line, because it requires a DNS lookup to complete before the request is finished. Default is false (= disabled).
true
%h
false
Mojolicious::Plugin::AccessLog inherits all methods from Mojolicious::Plugin and implements the following new ones.
register
$plugin->register( Mojolicious->new, { log => '/var/log/mojo/access.log', format => 'combined', } );
Register plugin hooks in Mojolicious application.
Mojolicious, Plack::Middleware::AccessLog, Catalyst::Plugin::AccessLog, http://httpd.apache.org/docs/2.0/mod/mod_log_config.html.
Many thanks to Tatsuhiko Miyagawa for Plack::Middleware::AccessLog and Andrew Rodland for Catalyst::Plugin::AccessLog. Mojolicious:Plugin::AccessLog borrows a lot of code and ideas from those modules.
Mojolicious:Plugin::AccessLog
Bernhard Graf <graf(a)cpan.org>
Copyright (C) 2012 Bernhard Graf
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/ for more information.
To install Mojolicious::Plugin::AccessLog, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::AccessLog
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::AccessLog
For more information on module installation, please visit the detailed CPAN module installation guide.