lib/Pg/Loader/Log.pm

filter: Statementstmt 34.2% 26 / 76 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 61.5% 8 / 13 Podpod 0.0% 0 / 3 totaltotal 24.6% 34 / 138 CC 19 SCAR 34.4
CC
19
Cov
23%
l4p_config
72.0
log_reject_errors
30.0
log_rejected_data
30.0
CRAP 31.2
« lib/Pg/Loader/Misc_2.pm ↑ Summary script/pgloader.pl »
1  
2 # Copyright (C) 2008 Ioannis Tambouras <ioannis@cpan.org>. All rights reserved.
3 # LICENSE: GPLv3, eead licensing terms at http://www.fsf.org .
4  
5 package Pg::Loader::Log;
6  
7 5 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Log::Log4perl qw( :easy );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Log::Log4perl::Layout;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Log::Log4perl::Level;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 our $VERSION = '0.12';
17 5 our @EXPORT = qw(
18 l4p_config _main_logger
19 log_rejected_data log_reject_errors
20 );
21  
22 0 ▶sub l4p_config {
Subroutine l4p_config: not called CC=8 SCAR=42.8
Pod undocumented
23 0 my ($c, $rej_data, $rej_log) = @_ ;
24 0 ▶ $c->{loglevel} //= 2;
Condition0%0/2
$c->{"loglevel"} //= 2
l!l
00
MC/DC0%0/1
$c->{"loglevel"} //= 2
$c->{"loglevel"}
Truth table0%0/2
A
A= $c->{"loglevel"}
Aresult
11
00
25 0 ▶ $c->{loglevel} < 1 and $c->{loglevel} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"loglevel"} < 1 and $c->{"loglevel"} = 1 0 0 0
26 0 ▶ $c->{loglevel} > 4 and $c->{loglevel} = 4;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"loglevel"} > 4 and $c->{"loglevel"} = 4 0 0 0
27 0 ▶ $c->{verbose} and $c->{loglevel} = 3;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"verbose"} and $c->{"loglevel"} = 3 0 0 0
28 0 ▶ $c->{debug} and $c->{loglevel} = 4;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"debug"} and $c->{"loglevel"} = 4 0 0 0
29 0 ▶ $c->{quiet} and $c->{loglevel} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"quiet"} and $c->{"loglevel"} = 1 0 0 0
30 0 my $level = (5-$c->{loglevel})*10_000 ;
31 0 ▶ _main_logger() ->level( $level//$INFO );
Condition0%0/3
$level // $Pg::Loader::Log::INFO
l!l&&r!l&&!r
000
MC/DC0%0/2
$level // $Pg::Loader::Log::INFO
$level $Pg::Loader::Log::INFO
Truth table0%0/3
A // B
A= $levelB= $Pg::Loader::Log::INFO
ABresult
1X1
011
000
32 }
33  
34 0 ▶sub _main_logger {
Subroutine _main_logger: not called CC=1 SCAR=6.9
35 0 my $main = get_logger('Pg::Loader');
36 0 my $layout = Log::Log4perl::Layout::PatternLayout->new( '%m%n' );
37 0 my $appender = Log::Log4perl::Appender->new(
38 'Log::Log4perl::Appender::File',
39 mode => 'append',
40 name => 'stdio',
41 filename => '/dev/tty');
42 # config logger
43 0 $appender->layout( $layout );
44 0 $main->add_appender( $appender);
45 0 $main;
46 }
47  
48 0 ▶sub _stack_logger {
Subroutine _stack_logger: not called CC=4 SCAR=30.0
49 0 my ($file, $mode, $pattern) = @_ ;
50 0 ▶ return unless $file || $mode ;
Branch: 1 branch
BranchTrueFalseTotal
unless $file or $mode 0 0 0
Condition0%0/3
$file or $mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$file or $mode
$file $mode
Truth table0%0/3
A or B
A= $fileB= $mode
ABresult
1X1
011
000
51 0 ▶ $pattern //= '%m%n';
Condition0%0/2
$pattern //= "%m%n"
l!l
00
MC/DC0%0/1
$pattern //= "%m%n"
$pattern
Truth table0%0/2
A
A= $pattern
Aresult
11
00
52  
53 ### Set each logger to a different name
54 0 state $name++;
55 0 my $l = get_logger( $name );
56 0 my $layout = Log::Log4perl::Layout::PatternLayout->new( $pattern );
57 0 my $appender = new Log::Log4perl::Appender
58 'Log::Log4perl::Appender::File',
59 mode => $mode ,
60 filename => $file ,
61 recreate => 0,
62 recreate_signal => 'USR1';
63
64 ### Config Logger
65 0 $appender->layout( $layout );
66 0 $l->add_appender( $appender);
67 0 $l->level( $INFO );
68 0 $l;
69 }
70  
71  
72 0 ▶sub log_reject_errors {
Subroutine log_reject_errors: not called CC=5 SCAR=34.0
Pod undocumented
73 0 my ( $s, $errstr, $section ) = @_;
74 0 ▶ return unless $s->{reject_log};
Branch: 1 branch
BranchTrueFalseTotal
unless $s->{"reject_log"} 0 0 0
75 0 my $file = $s->{reject_log};
76 0 state $last_section ;
77 0 ▶ $last_section //= 'new';
Condition0%0/2
$last_section //= "new"
l!l
00
MC/DC0%0/1
$last_section //= "new"
$last_section
Truth table0%0/2
A
A= $last_section
Aresult
11
00
78 0 my $l;
79 0 ▶ if ( $last_section ne $section ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_section ne $section) { } 0 0 0
80 0 $last_section = $section;
81 0 $l = _stack_logger ($file, 'clobber', '%m%n') ;
82 }else{
83 0 $l = _stack_logger ($file, 'append', '%m%n' ) ;
84 };
85 0 ▶ $l->info( $errstr ) if $errstr;
Branch: 1 branch
BranchTrueFalseTotal
if $errstr 0 0 0
86 }
87  
88  
89  
90 0 ▶sub log_rejected_data {
Subroutine log_rejected_data: not called CC=5 SCAR=34.0
Pod undocumented
91 # Error Checking
92 0 my ( $s, $section) = @_ ;
93 0 ▶ return unless $s->{reject_data};
Branch: 1 branch
BranchTrueFalseTotal
unless $s->{"reject_data"} 0 0 0
94 0 my $file = $s->{reject_data};
95 0 ▶ return unless Log::Log4perl::NDC->get();
Branch: 1 branch
BranchTrueFalseTotal
unless "Log::Log4perl::NDC"->get 0 0 0
96 0 state $last_section ;
97 0 ▶ $last_section //= 'new';
Condition0%0/2
$last_section //= "new"
l!l
00
MC/DC0%0/1
$last_section //= "new"
$last_section
Truth table0%0/2
A
A= $last_section
Aresult
11
00
98 0 my $l;
99 0 ▶ if ( $last_section ne $section ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_section ne $section) { } 0 0 0
100 0 $last_section = $section;
101 0 $l = _stack_logger ($file, 'clobber', ' %x%n') ;
102 }else{
103 0 $l = _stack_logger ($file, 'append' , ' %x%n') ;
104 };
105 0 $l->info( ) ;
106 0 Log::Log4perl::NDC->remove;
107 }
108  
109  
110 5 1;
111 __END__
« lib/Pg/Loader/Misc_2.pm ↑ Summary script/pgloader.pl »