Plack-Middleware-Log-Contextual
view release on metacpan or search on metacpan
use strict;
use Test::More;
use Plack::Test;
use Plack::Builder;
use HTTP::Request::Common;
my $app = sub {
my $env = shift;
use Log::Contextual qw(:log);
if ($env->{PATH_INFO} eq '/streaming') {
return sub {
my $r = shift;
log_fatal { "Streaming foo" };
$r->([ 200, [ 'Content-Type', 'text/plain' ], [ "Hello" ] ]);
};
}
log_fatal { "Foo" };
log_debug { "debugging" };
test_psgi $standalone, sub {
my $cb = shift;
my $res = $cb->(GET "/");
is $res->code, 200;
is @logs, 1;
is $logs[0], "[fatal] Foo\n";
@logs = ();
$res = $cb->(GET "/streaming");
is $res->code, 200;
is $res->content, "Hello";
is @logs, 1;
is $logs[0], "[fatal] Streaming foo\n";
};
# PSGI logger
@logs = ();
my $psgi = builder {
( run in 0.247 second using v1.01-cache-2.11-cpan-4d50c553e7e )