File Coverage

blib/lib/Kelp/Module/Logger/Log4perl.pm
Criterion Covered Total %
statement 17 17 100.0
branch 1 2 50.0
condition 2 2 100.0
subroutine 5 5 100.0
pod 0 1 0.0
total 25 27 92.5


line stmt bran cond sub pod time code
1             package Kelp::Module::Logger::Log4perl;
2             our $VERSION = "0.001";
3             $VERSION = eval $VERSION;
4              
5 1     1   341800 use Kelp::Base 'Kelp::Module::Logger';
  1         3  
  1         14  
6 1     1   25909 use Log::Log4perl qw( :levels );
  1         72895  
  1         12  
7 1     1   201 use Data::Dumper;
  1         7  
  1         419  
8              
9             attr 'category' => '';
10              
11             sub _logger {
12 4     4   50136 my ( $self, %args ) = @_;
13            
14 4         53 Log::Log4perl->init($args{conf});
15              
16 4   100     16422 return Log::Log4perl->get_logger($args{category} || '');
17             }
18              
19             # Override because Log4perl has own configurable layouts.
20             sub message {
21 16     16 0 127164 my ($self, $level, @messages) = @_;
22              
23 16         145 my %LEVELS_map = (
24             'trace' => $TRACE,
25             'debug' => $DEBUG,
26             'info' => $INFO,
27             'warn' => $WARN,
28             'error' => $ERROR,
29             'fatal' => $FATAL,
30             'always' => $OFF,
31             );
32            
33 16         48 for (@messages) {
34 16 50       48 my $message = ref($_) ? Dumper($_) : $_;
35 16         98 $self->{logger}->log( $LEVELS_map{$level}, $message );
36             }
37             }
38              
39             1;
40              
41             __END__