Skip to content

Commit

Permalink
Merge 14cfc13 into 53ff7dc
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Sep 5, 2013
2 parents 53ff7dc + 14cfc13 commit 6973bad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Plack/Middleware/LogDispatch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ sub call {
$env->{'psgix.logger'} = sub {
my $args = shift;
$args->{level} = 'critical' if $args->{level} eq 'fatal';

if ( ref $args->{message} && ref $args->{message} ne 'CODE' ) {
$args->{message} .= q{};
}

$self->logger->log(%$args);
};

Expand Down
17 changes: 16 additions & 1 deletion t/Plack-Middleware/log_dispatch.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ use HTTP::Request::Common;
use Log::Dispatch;
use Log::Dispatch::Array;

package Stringify;
use overload q{""} => sub { 'stringified object' };
sub new { bless {}, shift }

package main;

my @logs;

my $logger = Log::Dispatch->new;
Expand All @@ -19,6 +25,9 @@ $logger->add(Log::Dispatch::Array->new(
my $app = sub {
my $env = shift;
$env->{'psgix.logger'}->({ level => "debug", message => "This is debug" });
$env->{'psgix.logger'}->({ level => "info", message => sub { 'code ref' } });
$env->{'psgix.logger'}->({ level => "notice", message => Stringify->new() });

return [ 200, [], [] ];
};

Expand All @@ -28,9 +37,15 @@ test_psgi $app, sub {
my $cb = shift;
my $res = $cb->(GET "/");

is @logs, 1;
is @logs, 3;
is $logs[0]->{level}, 'debug';
is $logs[0]->{message}, 'This is debug';

is $logs[1]->{level}, 'info';
is $logs[1]->{message}, 'code ref';

is $logs[2]->{level}, 'notice';
is $logs[2]->{message}, 'stringified object';
};

done_testing;

0 comments on commit 6973bad

Please sign in to comment.