blib/lib/Plack/Middleware/Log4perl.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 40 CC 3 SCAR 16.7
CC
3
Cov
0%
prepare_app
12.0
call
2.0
BEGIN
2.0
CRAP 5.3
1 package Plack::Middleware::Log4perl;
2 use strict;
3 use parent qw(Plack::Middleware);
4 use Plack::Util::Accessor qw(category logger conf);
5 use Carp ();
6  
7 sub prepare_app {
8 my $self = shift;
9  
10 if ($self->conf) {
11 require Log::Log4perl;
12 Log::Log4perl::init($self->conf);
13 }
14  
15 # NOTICE: if category = '0' you must not change it by '' (root logger)
16 $self->logger( Log::Log4perl->get_logger( defined $self->category ? $self->category : '' ) );
17 }
18  
19 sub call {
20 my($self, $env) = @_;
21  
22 $env->{'psgix.logger'} = sub {
23 my $args = shift;
24 my $level = $args->{level};
25 local $Log::Log4perl::caller_depth
26 = $Log::Log4perl::caller_depth + 1;
27 $self->logger->$level($args->{message});
28 };
29  
30 $self->app->($env);
31 }
32  
33 1;
34  
35 __END__