Skip to content

Commit

Permalink
made %{...}t strftime log format work in Plack::Middleware::AccessLog
Browse files Browse the repository at this point in the history
  • Loading branch information
beppu committed Oct 23, 2009
1 parent 6a9b0d4 commit 7e5e76c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Plack/Middleware/AccessLog.pm
Expand Up @@ -79,7 +79,7 @@ sub log_line {

$fmt =~ s{
(?:
\%\{([\w\-]+)\}([a-z]) |
\%\{(.+?)\}([a-z]) |
\%(?:[<>])?([a-z\%])
)
}{ $1 ? $block_handler->($1, $2) : $char_handler->($3) }egx;
Expand Down
6 changes: 4 additions & 2 deletions t/Plack-Middleware/access_log.t
Expand Up @@ -4,11 +4,12 @@ use Test::More;
use HTTP::Request::Common;
use Plack::Test;
use Plack::Builder;
use POSIX;

my $log;
my $handler = builder {
enable "Plack::Middleware::AccessLog",
logger => sub { $log .= "@_" }, format => "%{Host}i %{Content-Type}o";
logger => sub { $log .= "@_" }, format => "%{Host}i %{Content-Type}o %{%m %y}t";
sub { [ 200, [ 'Content-Type' => 'text/plain' ], [ 'OK' ] ] };
};

Expand All @@ -26,7 +27,8 @@ my $test_req = sub {
$req->header("Host" => "example.com");
$test_req->($req);
chomp $log;
is $log, 'example.com text/plain';
my $month_year = POSIX::strftime('%m %y', localtime);
is $log, "example.com text/plain [$month_year]";
}

done_testing;

0 comments on commit 7e5e76c

Please sign in to comment.