Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Documentation for AccessLog middleware format fields #278

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 6 deletions.
  1. +28 −6 lib/Plack/Middleware/AccessLog.pm
View
34 lib/Plack/Middleware/AccessLog.pm
@@ -8,8 +8,8 @@ use Carp ();
use Plack::Util;
my %formats = (
- common => "%h %l %u %t \"%r\" %>s %b",
- combined => "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"",
+ common => '%h %l %u %t "%r" %>s %b',
+ combined => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"',
);
use POSIX ();
@@ -64,7 +64,7 @@ sub log_line {
h => sub { $env->{REMOTE_ADDR} || '-' },
l => sub { '-' },
u => sub { $env->{REMOTE_USER} || '-' },
- t => sub { "[" . $strftime->("%d/%b/%Y:%H:%M:%S %z", localtime) . "]" },
+ t => sub { "[" . $strftime->('%d/%b/%Y:%H:%M:%S %z', localtime) . "]" },
r => sub { _safe($env->{REQUEST_METHOD}) . " " . _safe($env->{REQUEST_URI}) .
" " . $env->{SERVER_PROTOCOL} },
s => sub { $status },
@@ -151,11 +151,33 @@ default C<development> environment.
=item format
enable "Plack::Middleware::AccessLog",
- format => "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"";
+ format => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"';
Takes a format string (or a preset template C<combined> or C<custom>)
-to specify the log format. This middleware implements subset of
-Apache's LogFormat templates.
+to specify the log format. This middleware implements a subset of
+L<Apache's LogFormat templates|http://httpd.apache.org/docs/2.0/mod/mod_log_config.html>:
+
+ %% 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
+ %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 -
+
+Some of these format fields are only supported by middleware that subclasses C<AccessLog>.
+
+In addition, custom values can be referenced, using C<%{name}>,
+with one of the mandatory modifier flags C<i>, C<o> or C<t>:
+
+ %{variable-name}i HTTP_VARIABLE_NAME value from the PSGI environment
+ %{header-name}o header-name header
+ %{time-format]t localtime in the specified strftime format
=item logger
Something went wrong with that request. Please try again.