blib/lib/MojoX/Log/Log4perl.pm

filter: Statementstmt 87.5% 63 / 72 Branchbran 64.2% 9 / 14 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 83.3% 20 / 24 Podpod 71.4% 10 / 14 totaltotal 83.0% 108 / 130 CC 10 SCAR 7.4
CC
10
Cov
84%
format
6.0
is_level
3.2
new
3.0
CRAP 2.1
↑ Summary
1 package MojoX::Log::Log4perl;
2 6 ▶use Mojo::Base 'Mojo::EventEmitter';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 our $VERSION = '0.12';
9  
10 3 ▶has history => sub { [] };
Subroutine __ANON__: called CC=1 SCAR=0.0
11 6 has max_history_size => 10;
12  
13 6 my $format_warning_was_shown = 0;
14  
15 # development notes: Mojo::Log provides 'path' 'handle' and 'format'
16 # to handle log location and formatting. Those make no sense in a Log4perl
17 # environment (where you can set appenders as you wish) so they are
18 # not implemented here; 'format' simply returns the passed-in strings joined by
19 # newlines as otherwise Mojo::Log complains (RT #98034).
20 0 ▶sub path { warn 'path() is not implemented in MojoX::Log::Log4perl. Please use appenders.' }
Subroutine path: not called CC=1 SCAR=6.9
Pod undocumented
21 0 ▶sub handle { warn 'handle() is not implemented in MojoX::Log::Log4perl. Please use appenders.' }
Subroutine handle: not called CC=1 SCAR=6.9
Pod undocumented
22 0 ▶sub format {
Subroutine format: not called CC=2 SCAR=17.9
Pod undocumented
23 0 ▶ if (!$format_warning_was_shown) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($format_warning_was_shown) 0 0 0
24 0 $format_warning_was_shown = 1;
25 0 warn 'format() is not properly implemented in MojoX::Log::Log4perl. Please use appenders.';
26 }
27 0 ▶ return sub { '[' . localtime(shift) . '] [' . shift() . '] ' . join("\n", @_, '') };
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 }
29  
30 # development notes: Mojo::Log provides 'context'
31 # Mojo::Log (Mojolicious 8.23) was updated to add method context which
32 # needs to exist here or we die
33 1 ▶sub context {
Subroutine context: called CC=1 SCAR=0.0
Pod undocumented
34 1 my ($self) = @_;
35 1 return $self;
36 }
37  
38 5 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
39 5 my ($class, $conf_file, $watch) = (@_);
40  
41 5 ▶ $conf_file ||= {
Condition100%2/2
$conf_file ||= {"log4perl.rootLogger", "DEBUG, SCREEN", "log4perl.appender.SCREEN", "Log::Log4perl::Appender::Screen", "log4perl.appender.SCREEN.layout", "PatternLayout", "log4perl.appender.SCREEN.layout.ConversionPattern", "[%d] [mojo] [%p] %m%n"}
l!l
32
MC/DC100%1/1
$conf_file ||= {"log4perl.rootLogger", "DEBUG, SCREEN", "log4perl.appender.SCREEN", "Log::Log4perl::Appender::Screen", "log4perl.appender.SCREEN.layout", "PatternLayout", "log4perl.appender.SCREEN.layout.ConversionPattern", "[%d] [mojo] [%p] %m%n"}
$conf_file
Truth table100%2/2
A
A= $conf_file
Aresult
11
00
42 'log4perl.rootLogger' => 'DEBUG, SCREEN',
43 'log4perl.appender.SCREEN' => 'Log::Log4perl::Appender::Screen',
44 'log4perl.appender.SCREEN.layout' => 'PatternLayout',
45 'log4perl.appender.SCREEN.layout.ConversionPattern' => '[%d] [mojo] [%p] %m%n',
46 };
47  
48 5 ▶ if ($watch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($watch) { } 0 5 5
49 0 Log::Log4perl::init_and_watch($conf_file, $watch);
50 }
51 else {
52 5 Log::Log4perl->init_once($conf_file);
53 }
54  
55 5 my $self = $class->SUPER::new();
56 5 $self->on( message => \&_message );
57 5 return $self;
58 }
59  
60 # Hmm. Ah, a picture of my mommy.
61 {
62 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 6 for my $level (
64 qw/ trace
65 debug
66 info
67 warn
68 error
69 fatal
70 logwarn
71 logdie
72 error_warn
73 error_die
74 logcarp
75 logcluck
76 logcroak
77 logconfess
78 / ) {
79  
80 84 *{ __PACKAGE__ . "::$level" } =
81 15 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
82 15 return shift->emit( message => $level => @_ );
83 84 };
84 }
85 }
86  
87 11 ▶sub _message {
Subroutine _message: called CC=3 SCAR=11.0
88 11 my ($self, $level, @message ) = @_;
89 11 my $depth = 3;
90 11 local $Log::Log4perl::caller_depth
91 = $Log::Log4perl::caller_depth + $depth;
92  
93 11 ▶ if ($self->_get_logger( $depth )->$level( @message )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_logger($depth)->$level(@message)) 7 4 11
94 7 my $history = $self->history;
95 7 my $max = $self->max_history_size;
96 7 push @$history => [ time, $level, @message ];
97 7 ▶ splice (@$history, 0, scalar @$history - $max)
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$history > $max 1 6 7
98 if scalar @$history > $max;
99 }
100 11 return $self;
101 }
102  
103 1 ▶sub log { shift->emit('message', lc(shift), @_) }
Subroutine log: called CC=1 SCAR=0.0
Pod documented
104  
105 1 ▶sub is_trace { shift->_get_logger->is_trace }
Subroutine is_trace: called CC=1 SCAR=0.0
Pod documented
106 3 ▶sub is_debug { shift->_get_logger->is_debug }
Subroutine is_debug: called CC=1 SCAR=0.0
Pod documented
107 1 ▶sub is_info { shift->_get_logger->is_info }
Subroutine is_info: called CC=1 SCAR=0.0
Pod documented
108 1 ▶sub is_warn { shift->_get_logger->is_warn }
Subroutine is_warn: called CC=1 SCAR=0.0
Pod documented
109 1 ▶sub is_error { shift->_get_logger->is_error }
Subroutine is_error: called CC=1 SCAR=0.0
Pod documented
110 1 ▶sub is_fatal { shift->_get_logger->is_fatal }
Subroutine is_fatal: called CC=1 SCAR=0.0
Pod documented
111  
112 12 ▶sub is_level {
Subroutine is_level: called CC=3 SCAR=11.8
Pod documented
113 12 my ($self, $level) = (@_);
114 12 ▶ return 0 unless $level;
Branch: 1 branch
BranchTrueFalseTotal
unless $level 0 12 12
115  
116 12 ▶ if ($level =~ m/^(?:trace|debug|info|warn|error|fatal)$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level =~ /^(?:trace|debug|info|warn|error|fatal)$/ou) { } 12 0 12
117 12 my $is_level = "is_$level";
118 12 return $self->_get_logger->$is_level;
119 }
120 else {
121 0 return 0;
122 }
123 }
124  
125 11 ▶sub level {
Subroutine level: called CC=2 SCAR=6.9
Pod documented
126 11 my ($self, $level) = (@_);
127 11 my $logger = $self->_get_logger;
128  
129 11 require Log::Log4perl::Level;
130 11 ▶ if ($level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) { } 9 2 11
131 9 return $logger->level( Log::Log4perl::Level::to_priority(uc $level) );
132 }
133 else {
134 2 return Log::Log4perl::Level::to_level( $logger->level() );
135 }
136 }
137  
138 # $_[0] == $self, $_[1] == optional caller level (defaults to 1)
139 42 ▶sub _get_logger {
Subroutine _get_logger: called CC=2 SCAR=6.9
140 42 ▶ return Log::Log4perl->get_logger( scalar caller( $_[1] || 1 ) );
Condition100%2/2
$_[1] || 1
l!l
1131
MC/DC100%1/1
$_[1] || 1
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
141 }
142  
143 6 1;
144 __END__
↑ Summary