blib/lib/Shipwright/Logger.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 80.0% 8 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 89.6% 52 / 58 CC 7 SCAR 12.8
CC
7
Cov
90%
_initialize_log4perl
6.3
new
2.0
BEGIN
1.0
CRAP 3.6
« blib/lib/Shipwright/Backend.pm ↑ Summary blib/lib/Shipwright/Util/CleanINC.pm »
1 package Shipwright::Logger;
2 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use Shipwright::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Shipwright::Logger - Log
11  
12 =head1 SYNOPSIS
13  
14 use Shipwright::Logger;
15  
16 =head2 new
17  
18 =cut
19  
20 13 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
21 13 my $class = shift;
22  
23 13 my $self = {};
24 13 bless $self, $class;
25  
26 13 ▶ if ( not Log::Log4perl->initialized ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Log::Log4perl"->initialized) 8 5 13
27 8 $class->_initialize_log4perl(@_);
28 }
29 13 return $self;
30 }
31  
32 8 ▶sub _initialize_log4perl {
Subroutine _initialize_log4perl: called CC=6 SCAR=18.4
33 8 my $class = shift;
34 8 my $ref = $_[0];
35  
36 8 my ( $log_level, $log_file );
37  
38 8 ▶ if ( blessed $ref ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($ref)) { } 0 8 8
elsif (ref $ref) { } 1 7 8
39  
40 # so it's an object, we assuming it has log_level and log_file subs
41 0 $log_level = $ref->log_level;
42 0 $log_file = $ref->log_file;
43 }
44 elsif ( ref $ref ) {
45  
46 # it's a hashref
47 1 $log_level = $ref->{log_level};
48 1 $log_file = $ref->{log_file};
49 }
50 else {
51  
52 # not ref at all
53 7 my %hash = @_;
54 7 $log_level = $hash{log_level};
55 7 $log_file = $hash{log_file};
56 }
57  
58 8 ▶ $log_level = $log_level ? uc $log_level : 'FATAL';
Branch: 1 branch
BranchTrueFalseTotal
$log_level ? : 7 1 8
59 8 ▶ $log_file ||= '-';
Condition50%1/2
$log_file ||= "-"
l!l
08
MC/DC0%0/1
$log_file ||= "-"
$log_file
Truth table50%1/2
A
A= $log_file
Aresult
11
00
60 8 ▶ my %default = (
Branch: 1 branch
BranchTrueFalseTotal
$log_file eq '-' ? : 8 0 8
61 'log4perl.rootLogger' => "$log_level,File",
62 'log4perl.appender.File.filename' => $log_file,
63 'log4perl.appender.File' => 'Log::Log4perl::Appender::File',
64 'log4perl.appender.File.stderr' => 1,
65 'log4perl.appender.File.layout' =>
66 'Log::Log4perl::Layout::PatternLayout',
67 'log4perl.appender.File.layout.ConversionPattern' =>
68 $log_file eq '-' ? '%m%n' : '%d %p> %F{1}:%L %M - %m%n',
69 );
70  
71 8 Log::Log4perl->init( \%default );
72 }
73  
74 15 1;
75  
76 __END__
« blib/lib/Shipwright/Backend.pm ↑ Summary blib/lib/Shipwright/Util/CleanINC.pm »