blib/lib/Dancer/Logger/Log4perl.pm

filter: Statementstmt 47.7% 21 / 44 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 1 / 1 totaltotal 38.3% 28 / 73 CC 12 SCAR 38.5
CC
12
Cov
33%
init
90.0
_log
20.0
BEGIN
1.0
CRAP 47.2
↑ Summary
1 package Dancer::Logger::Log4perl;
2  
3 #
4 # ABSTRACT: Dancer adapter for Log::Log4perl
5 #
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use base 'Dancer::Logger::Abstract';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Dancer::Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Dancer::ModuleLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 our $VERSION = '0.9.0';
16  
17 1 my $default_config = <<'END_OF_CONFIG';
18 log4perl.logger = ALL, Screen
19 log4perl.appender.Screen = Log::Log4perl::Appender::Screen
20 log4perl.appender.Screen.stderr = 1
21 log4perl.appender.Screen.stdout = 0
22 log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
23 log4perl.appender.Screen.layout.ConversionPattern = [%d] [%-5p] %m%n
24 END_OF_CONFIG
25  
26 0 ▶sub init {
Subroutine init: not called CC=9 SCAR=45.0
Pod documented
27 0 my $self = shift;
28 0 $self->SUPER::init(@_);
29  
30 0 my $conf = Dancer::Config::setting('log4perl');
31 0 ▶ my $class = $conf->{tiny} ? 'Log::Log4perl::Tiny' : 'Log::Log4perl';
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'tiny'} ? : 0 0 0
32 0 $self->{class} = $class;
33  
34 0 ▶ unless ( Dancer::ModuleLoader->require($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Dancer::ModuleLoader"->require($class)) 0 0 0
35 0 carp "unable to load $class";
36 0 return;
37 }
38  
39 0 ▶ if ( ! $conf->{no_init} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf->{"no_init"}) 0 0 0
40 0 ▶ if ( $conf->{tiny} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{'tiny'}) { } 0 0 0
41 0 my $logger = $class->get_logger();
42 0 for my $accessor (qw( fh level layout format )) {
43 0 ▶ if ( exists $conf->{$accessor} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $conf->{$accessor}) 0 0 0
44 0 $logger->$accessor($conf->{$accessor});
45 }
46 }
47 } else {
48 my $l4p_conf =
49 exists $conf->{config_file} ? $conf->{config_file}
50 : exists $conf->{config} ? \$conf->{config}
51 0 ▶ : \$default_config;
Branch: 2 branches
BranchTrueFalseTotal
exists $conf->{'config_file'} ? : 0 0 0
exists $conf->{'config'} ? : 0 0 0
52 0 Log::Log4perl::init($l4p_conf);
53 }
54 }
55  
56 0 $self->{logger} = $class->get_logger();
57 }
58  
59 0 ▶sub _log {
Subroutine _log: not called CC=4 SCAR=30.0
60 0 my ($self, $level, $message) = @_;
61  
62 0 ▶ $level = 'warn' if $level eq 'warning';
Branch: 1 branch
BranchTrueFalseTotal
if $level eq "warning" 0 0 0
63 0 ▶ $level = 'trace' if $level eq 'core';
Branch: 1 branch
BranchTrueFalseTotal
if $level eq "core" 0 0 0
64 0 my $format_level = $level;
65  
66 # Adjust the caller level since we've introduced additional levels. Does not apply to Tiny module.
67 0 ▶ local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 3 if $self->{class} eq 'Log::Log4perl';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"class"} eq "Log::Log4perl" 0 0 0
68  
69 0 $self->{logger}->$level($self->format_message($format_level => $message));
70 }
71  
72 1 1;
73 __END__
↑ Summary