File: //usr/local/share/man/man3/Plack::Middleware::AccessLog.3pm
.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Plack::Middleware::AccessLog 3"
.TH Plack::Middleware::AccessLog 3 "2020-11-30" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Plack::Middleware::AccessLog \- Logs requests like Apache's log format
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\& # in app.psgi
\& use Plack::Builder;
\&
\& builder {
\& enable "Plack::Middleware::AccessLog", format => "combined";
\& $app;
\& };
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Plack::Middleware::AccessLog forwards the request to the given app and
logs request and response details to the logger callback. The format
can be specified using Apache-like format strings (or \f(CW\*(C`combined\*(C'\fR or
\&\f(CW\*(C`common\*(C'\fR for the default formats). If none is specified \f(CW\*(C`combined\*(C'\fR is
used.
.PP
This middleware uses calculable Content-Length by checking body type,
and cannot log the time taken to serve requests. It also logs the
request \fBbefore\fR the response is actually sent to the client. Use
Plack::Middleware::AccessLog::Timed if you want to log details
\&\fBafter\fR the response is transmitted (more like a real web server) to
the client.
.PP
This middleware is enabled by default when you run plackup as a
default \f(CW\*(C`development\*(C'\fR environment.
.SH "CONFIGURATION"
.IX Header "CONFIGURATION"
.IP "format" 4
.IX Item "format"
.Vb 2
\& enable "Plack::Middleware::AccessLog",
\& format => \*(Aq%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User\-agent}i"\*(Aq;
.Ve
.Sp
Takes a format string (or a preset template \f(CW\*(C`combined\*(C'\fR or \f(CW\*(C`custom\*(C'\fR)
to specify the log format. This middleware uses Apache::LogFormat::Compiler to
generate access_log lines. See more details on perldoc Apache::LogFormat::Compiler
.Sp
.Vb 10
\& %% a percent sign
\& %h REMOTE_ADDR from the PSGI environment, or \-
\& %l remote logname not implemented (currently always \-)
\& %u REMOTE_USER from the PSGI environment, or \-
\& %t [local timestamp, in default format]
\& %r REQUEST_METHOD, REQUEST_URI and SERVER_PROTOCOL from the PSGI environment
\& %s the HTTP status code of the response
\& %b content length of the response
\& %T custom field for handling times in subclasses
\& %D custom field for handling sub\-second times in subclasses
\& %v SERVER_NAME from the PSGI environment, or \-
\& %V HTTP_HOST or SERVER_NAME from the PSGI environment, or \-
\& %p SERVER_PORT from the PSGI environment
\& %P the worker\*(Aqs process id
\& %m REQUEST_METHOD from the PSGI environment
\& %U PATH_INFO from the PSGI environment
\& %q QUERY_STRING from the PSGI environment
\& %H SERVER_PROTOCOL from the PSGI environment
.Ve
.Sp
Some of these format fields are only supported by middleware that subclasses \f(CW\*(C`AccessLog\*(C'\fR.
.Sp
In addition, custom values can be referenced, using \f(CW\*(C`%{name}\*(C'\fR,
with one of the mandatory modifier flags \f(CW\*(C`i\*(C'\fR, \f(CW\*(C`o\*(C'\fR or \f(CW\*(C`t\*(C'\fR:
.Sp
.Vb 3
\& %{variable\-name}i HTTP_VARIABLE_NAME value from the PSGI environment
\& %{header\-name}o header\-name header in the response
\& %{time\-format]t localtime in the specified strftime format
.Ve
.IP "logger" 4
.IX Item "logger"
.Vb 3
\& my $logger = Log::Dispatch\->new(...);
\& enable "Plack::Middleware::AccessLog",
\& logger => sub { $logger\->log(level => \*(Aqdebug\*(Aq, message => @_) };
.Ve
.Sp
Sets a callback to print log message to. It prints to the \f(CW\*(C`psgi.errors\*(C'\fR
output stream by default.
.IP "char_handlers" 4
.IX Item "char_handlers"
.Vb 6
\& my $handlers = {
\& \*(Aqz\*(Aq => sub {
\& my ($env,$req) = @_;
\& return $env\->{HTTP_X_FORWARDED_FOR};
\& }
\& };
\&
\& enable "Plack::Middleware::AccessLog",
\& format => \*(Aq%z %{HTTP_X_FORWARDED_FOR|REMOTE_ADDR}Z\*(Aq,
\& char_handlers => $handlers;
.Ve
.Sp
Takes a hash reference and passes it to the underlying
Apache::LogFormat::Compiler's \f(CW\*(C`char_handlers\*(C'\fR. For more details see
\&\*(L"\s-1ADD CUSTOM FORMAT STRING\*(R"\s0 in Apache::LogFormat::Compiler.
.IP "block_handlers" 4
.IX Item "block_handlers"
.Vb 8
\& my $handlers = {
\& \*(AqZ\*(Aq => sub {
\& my ($block,$env,$req) = @_;
\& # block eq \*(AqHTTP_X_FORWARDED_FOR|REMOTE_ADDR\*(Aq
\& my ($main, $alt) = split(\*(Aq\e|\*(Aq, $args);
\& return exists $env\->{$main} ? $env\->{$main} : $env\->{$alt};
\& }
\& };
\&
\& enable "Plack::Middleware::AccessLog",
\& format => \*(Aq%z %{HTTP_X_FORWARDED_FOR|REMOTE_ADDR}Z\*(Aq,
\& block_handlers => $handlers;
.Ve
.Sp
Takes a hash reference and passes it to the underlying
Apache::LogFormat::Compiler's \f(CW\*(C`block_handlers\*(C'\fR. For more details see
\&\*(L"\s-1ADD CUSTOM FORMAT STRING\*(R"\s0 in Apache::LogFormat::Compiler.
.SH "AUTHORS"
.IX Header "AUTHORS"
Tatsuhiko Miyagawa
.PP
Masahiro Nagano
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Apache::LogFormat::Compiler, <http://httpd.apache.org/docs/2.2/mod/mod_log_config.html> Rack::CustomLogger