format
enable "Plack::Middleware::AccessLog",
format => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"';
Takes a format string (or a preset template "combined" or "custom") to specify the log format. This
middleware uses Apache::LogFormat::Compiler to generate access_log lines. See more details on perldoc
Apache::LogFormat::Compiler
%% 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's 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
Some of these format fields are only supported by middleware that subclasses "AccessLog".
In addition, custom values can be referenced, using "%{name}", with one of the mandatory modifier
flags "i", "o" or "t":
%{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
logger
my $logger = Log::Dispatch->new(...);
enable "Plack::Middleware::AccessLog",
logger => sub { $logger->log(level => 'debug', message => @_) };
Sets a callback to print log message to. It prints to the "psgi.errors" output stream by default.
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.