Plack::...cessLog(3)
π Plack::Middleware::AccessLog π
okay so bestie, this is a page from the User Contributed Perl Documentation for the module Plack::Middleware::AccessLog β it's the thing that goes in the Plack world. let's get into it, no cap π«Ά
β¨ NAME β¨
Plack::Middleware::AccessLog β logs requests like Apache's log format π
πΈ SYNOPSIS πΈ
# in app.psgi
use Plack::Builder;
builder {
enable "Plack::Middleware::AccessLog", format => "combined";
$app;
};
π¦ DESCRIPTION π¦
Plack::Middleware::AccessLog takes the request, hands it off to the app you gave it, and then writes the request-and-response deets out to the logger callback. the format is whatever Apache-style format string you want β or you can just say combined or common for the preset default formats. and if you don't say anything at all? combined it is, periodt.
this middleware figures out a calculable Content-Length by peeking at the body type, and ngl it cannot log how long serving the request took. it also logs the request before the response has actually been sent to the client. so if you want the details logged after the response is transmitted to the client (aka more like a real web server does it), go use Plack::Middleware::AccessLog::Timed instead π
oh and heads up: this middleware is enabled by default when you run plackup as a default development environment. it's just there, being iconic. β
π CONFIGURATION π
π format
enable "Plack::Middleware::AccessLog",
format => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"';
gives you a format string (or one of the preset templates combined or custom) to say what the log format should look like. under the hood this middleware uses Apache::LogFormat::Compiler to generate the access_log lines, so if you want the full lore, go check perldoc Apache::LogFormat::Compiler π
here's every format field, copy them exactly bestie:
%%β a percent sign π―%hβREMOTE_ADDRfrom the PSGI environment, or-%lβ remote logname β not implemented (currently always-)%uβREMOTE_USERfrom the PSGI environment, or-%tβ[local timestamp, in default format]%rβREQUEST_METHOD,REQUEST_URIandSERVER_PROTOCOLfrom 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_NAMEfrom the PSGI environment, or-%VβHTTP_HOSTorSERVER_NAMEfrom the PSGI environment, or-%pβSERVER_PORTfrom the PSGI environment%Pβ the worker's process id%mβREQUEST_METHODfrom the PSGI environment%UβPATH_INFOfrom the PSGI environment%qβQUERY_STRINGfrom the PSGI environment%HβSERVER_PROTOCOLfrom the PSGI environment
some of these format fields are only supported by middleware that subclasses AccessLog. so, yk, read the room π
in addition, you can reference custom values using %{name}, with one of the mandatory modifier flags i, o or t:
%{variable-name}iβHTTP_VARIABLE_NAMEvalue from the PSGI environment%{header-name}oβheader-nameheader in the response%{time-format]tβ localtime in the specified strftime format
π§ logger
my $logger = Log::Dispatch->new(...);
enable "Plack::Middleware::AccessLog",
logger => sub { $logger->log(level => 'debug', message => @_) };
sets a callback to print the log message to. by default it prints to the psgi.errors output stream. π
π char_handlers
my $handlers = {
'z' => sub {
my ($env,$req) = @_;
return $env->{HTTP_X_FORWARDED_FOR};
}
};
enable "Plack::Middleware::AccessLog",
format => '%z %{HTTP_X_FORWARDED_FOR|REMOTE_ADDR}Z',
char_handlers => $handlers;
takes a hash reference and passes it to the underlying Apache::LogFormat::Compiler's char_handlers. for more details see "ADD CUSTOM FORMAT STRING" in Apache::LogFormat::Compiler. π
π«Ά block_handlers
my $handlers = {
'Z' => sub {
my ($block,$env,$req) = @_;
# block eq 'HTTP_X_FORWARDED_FOR|REMOTE_ADDR'
my ($main, $alt) = split('\|', $args);
return exists $env->{$main} ? $env->{$main} : $env->{$alt};
}
};
enable "Plack::Middleware::AccessLog",
format => '%z %{HTTP_X_FORWARDED_FOR|REMOTE_ADDR}Z',
block_handlers => $handlers;
takes a hash reference and passes it to the underlying Apache::LogFormat::Compiler's block_handlers. for more details see "ADD CUSTOM FORMAT STRING" in Apache::LogFormat::Compiler. β¨
π AUTHORS π
- Tatsuhiko Miyagawa
- Masahiro Nagano
the way they built this and just handed it to us?? legends, fr fr π«‘
π₯ SEE ALSO π₯
Apache::LogFormat::Compiler,<http://httpd.apache.org/docs/2.2/mod/mod_log_config.html>Rack::CustomLogger
okay that's the whole page, bestie!! π this one ships with perl v5.42.3 and it's dated 2026-10-18 β the manual itself is Plack::...cessLog(3). go log something, slay, and drink some water. mwah π
πΈ
π¦ where this page comes from
- fedora 43: perl-Plack 1.0055-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-Plack 1.0055-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms