Lite/Logger.pm

filter: Statementstmt 25.5% 12 / 47 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 3 / 12 Podpod 0.0% 0 / 8 totaltotal 16.8% 15 / 89 CC 11 SCAR 18.1
CC
11
Cov
18%
new
12.0
_log_level
6.0
trace
6.0
CRAP 6.1
« Lite/Lock.pm ↑ Summary Lite/Credentials.pm »
1 ########################################################################
2 # Minimal STDERR logger — used when Log::Log4perl is not available
3 # Implements the same interface callers expect
4 ########################################################################
5 package Amazon::S3::Lite::Logger;
6  
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our $VERSION = '1.3.3';
11  
12 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 Readonly::Scalar our $LEVELS => {
14 TRACE => 5000,
15 DEBUG => 10_000,
16 INFO => 20_000,
17 WARN => 30_000,
18 ERROR => 40_000,
19 FATAL => 50_000,
20 };
21  
22 ########################################################################
23 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
24 ########################################################################
25 0 my ( $class, @args ) = @_;
26  
27 0 ▶ my $options = ref $args[0] ? $args[0] : {@args};
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 0 0 0
28  
29 0 my $self = bless $options, $class;
30 0 ▶ $self->{log_level} //= 'warn';
Condition0%0/2
$self->{"log_level"} //= "warn"
l!l
00
MC/DC0%0/1
$self->{"log_level"} //= "warn"
$self->{"log_level"}
Truth table0%0/2
A
A= $self->{"log_level"}
Aresult
11
00
31  
32 0 return $self;
33 }
34  
35 ########################################################################
36 0 ▶sub _log_level {
Subroutine _log_level: not called CC=2 SCAR=17.9
37 ########################################################################
38 0 my ($self) = @_;
39  
40 0 my $level = uc $self->{log_level};
41  
42 0 ▶ return $LEVELS->{$level} // 0;
Condition0%0/2
$Amazon::S3::Lite::Logger::LEVELS->{$level} // 0
l!l
00
MC/DC0%0/1
$Amazon::S3::Lite::Logger::LEVELS->{$level} // 0
$Amazon::S3::Lite::Logger::LEVELS->{$level}
Truth table0%0/2
A
A= $Amazon::S3::Lite::Logger::LEVELS->{$level}
Aresult
11
00
43 }
44  
45 ########################################################################
46 0 ▶sub trace { # silent
Subroutine trace: not called CC=2 SCAR=17.9
Pod undocumented
47 ########################################################################
48 0 my ( $self, $msg ) = @_;
49 0 ▶ return if $self->_log_level > $LEVELS->{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_log_level > $Amazon::S3::Lite::Logger::LEVELS->{"TRACE"} 0 0 0
50  
51 0 return print {*STDERR} "TRACE - $msg\n";
52 }
53  
54 ########################################################################
55 0 ▶sub debug {
Subroutine debug: not called CC=2 SCAR=17.9
Pod undocumented
56 ########################################################################
57 0 my ( $self, $msg ) = @_;
58 0 ▶ return if $self->_log_level > $LEVELS->{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_log_level > $Amazon::S3::Lite::Logger::LEVELS->{"DEBUG"} 0 0 0
59  
60 0 return print {*STDERR} "DEBUG - $msg\n";
61 }
62  
63 ########################################################################
64 0 ▶sub level {
Subroutine level: not called CC=2 SCAR=17.9
Pod undocumented
65 ########################################################################
66 0 my ( $self, $level ) = @_;
67  
68 0 ▶ return $self->_log_level
Branch: 1 branch
BranchTrueFalseTotal
unless $level 0 0 0
69 if !$level;
70  
71 0 $self->{log_level} = $level;
72  
73 0 return $level;
74 }
75  
76 ########################################################################
77 0 ▶sub info {
Subroutine info: not called CC=2 SCAR=17.9
Pod undocumented
78 ########################################################################
79 0 my ( $self, $msg ) = @_;
80 0 ▶ return if $self->_log_level > $LEVELS->{INFO};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_log_level > $Amazon::S3::Lite::Logger::LEVELS->{"INFO"} 0 0 0
81  
82 0 return print {*STDERR} "INFO - $msg\n";
83 }
84  
85 ########################################################################
86 0 ▶sub warn { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
Subroutine warn: not called CC=2 SCAR=17.9
Pod undocumented
87 ########################################################################
88 0 my ( $self, $msg ) = @_;
89 0 ▶ return if $self->_log_level > $LEVELS->{WARN};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_log_level > $Amazon::S3::Lite::Logger::LEVELS->{"WARN"} 0 0 0
90  
91 0 return print {*STDERR} "WARN - $msg\n";
92 }
93  
94 ########################################################################
95 0 ▶sub error {
Subroutine error: not called CC=2 SCAR=17.9
Pod undocumented
96 ########################################################################
97 0 my ( $self, $msg ) = @_;
98 0 ▶ return if $self->_log_level > $LEVELS->{ERROR};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_log_level > $Amazon::S3::Lite::Logger::LEVELS->{"ERROR"} 0 0 0
99  
100 0 return print {*STDERR} "ERROR - $msg\n";
101 }
102  
103 ########################################################################
104 0 ▶sub fatal {
Subroutine fatal: not called CC=2 SCAR=17.9
Pod undocumented
105 ########################################################################
106 0 my ( $self, $msg ) = @_;
107  
108 0 ▶ return if $self->_log_level > $LEVELS->{FATAL};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_log_level > $Amazon::S3::Lite::Logger::LEVELS->{"FATAL"} 0 0 0
109  
110 0 die "FATAL - $msg\n";
111 }
112  
113 3 1;
« Lite/Lock.pm ↑ Summary Lite/Credentials.pm »