AnyPAN/Logger.pm

filter: Statementstmt 70.7% 29 / 41 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 6 totaltotal 65.0% 41 / 63 CC 3 SCAR 5.0
CC
3
Cov
71%
format_log
3.0
write_log
2.0
_log
2.0
CRAP 1.6
« AnyPAN/Storage/Directory.pm ↑ Summary AnyPAN/RetryPolicy.pm »
1 package AnyPAN::Logger;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Class::Accessor::Lite ro => [qw/level/], new => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 my %LEVEL_MAP = (
11 error => 1000,
12 warn => 500,
13 info => 100,
14 debug => 10,
15 );
16  
17 0 ▶sub write_log { require Carp; Carp::croak('abstruct method') }
Subroutine write_log: not called CC=1 SCAR=6.9
Pod undocumented
18  
19 6 ▶sub format_log {
Subroutine format_log: called CC=2 SCAR=11.1
Pod undocumented
20 6 my ($self, $now, $level, $msg, $attr) = @_;
21 6 ▶ unless (defined $attr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $attr) 6 0 6
22 6 return sprintf '%s [%s] %s', $now->to_string(), uc $level, $msg;
23 }
24  
25 0 my $attr_str = do {
26 0 local $Data::Dumper::Terse = 1;
27 0 local $Data::Dumper::Indent = 0;
28 0 local $Data::Dumper::Sortkeys = 1;
29 0 Data::Dumper::Dumper($attr);
30 };
31 0 return sprintf '%s [%s] %s (%s)', $now->to_string(), uc $level, $msg, $attr_str;
32 }
33  
34 18 ▶sub _log {
Subroutine _log: called CC=2 SCAR=6.9
35 18 my ($self, $level, $msg, $attr) = @_;
36 18 ▶ return if $LEVEL_MAP{$level} < $LEVEL_MAP{$self->level};
Branch: 1 branch
BranchTrueFalseTotal
if $LEVEL_MAP{$level} < $LEVEL_MAP{$self->level} 12 6 18
37  
38 6 my $now = Time::Moment->now_utc();
39 6 my $payload = $self->format_log($now, $level, $msg, $attr);
40 6 $self->write_log($payload);
41 }
42  
43 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my ($self, $msg, $attr) = @_;
45 0 $self->_log(error => $msg, $attr);
46 }
47  
48 0 ▶sub warn {
Subroutine warn: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my ($self, $msg, $attr) = @_;
50 0 $self->_log(warn => $msg, $attr);
51 }
52  
53 6 ▶sub info {
Subroutine info: called CC=1 SCAR=0.0
Pod undocumented
54 6 my ($self, $msg, $attr) = @_;
55 6 $self->_log(info => $msg, $attr);
56 }
57  
58 12 ▶sub debug {
Subroutine debug: called CC=1 SCAR=0.0
Pod undocumented
59 12 my ($self, $msg, $attr) = @_;
60 12 $self->_log(debug => $msg, $attr);
61 }
62  
63 2 1;
64 __END__
« AnyPAN/Storage/Directory.pm ↑ Summary AnyPAN/RetryPolicy.pm »