lib/IRC/Indexer/Logger.pm

filter: Statementstmt 85.7% 36 / 42 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 3 totaltotal 76.8% 53 / 69 CC 8 SCAR 11.0
CC
8
Cov
81%
log_to
6.0
new
5.0
_create_logger
2.0
CRAP 3.0
« lib/IRC/Indexer/Report/Network.pm ↑ Summary script/ircindexer-single »
1 package IRC::Indexer::Logger;
2  
3 1 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Log::Handler;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod undocumented
13 2 my $self = {};
14 2 my $class = shift;
15 2 bless $self, $class;
16 ## Set up a Log::Handler for specified LogFile
17
18 2 my %args = @_;
19 2 $args{lc $_} = delete $args{$_} for keys %args;
20  
21 2 ▶ if ($args{devnull}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'devnull'}) { } 1 1 2
22 ## Sometimes it's useful to have a log object present,
23 ## but not necessarily logging anywhere:
24 1 $self->{DevNull} = 1;
25 } else {
26 $self->{LogFile} = $args{logfile}
27 1 ▶ || croak "No LogFile specified in new()";
Condition50%1/2
$args{'logfile'} || croak('No LogFile specified in new()')
l!l
10
MC/DC0%0/1
$args{'logfile'} || croak('No LogFile specified in new()')
$args{'logfile'}
Truth table50%1/2
A
A= $args{'logfile'}
Aresult
11
00
28 }
29 2 ▶ $self->{LogLevel} = $args{loglevel} || 'info' ;
Condition50%1/2
$args{'loglevel'} || 'info'
l!l
02
MC/DC0%0/1
$args{'loglevel'} || 'info'
$args{'loglevel'}
Truth table50%1/2
A
A= $args{'loglevel'}
Aresult
11
00
30
31 2 $self->logger( $self->_create_logger );
32
33 2 return $self
34 }
35  
36 2 ▶sub _create_logger {
Subroutine _create_logger: called CC=2 SCAR=6.9
37 2 my ($self) = @_;
38 2 my $logger = Log::Handler->new();
39 $logger->add(
40 file => {
41 maxlevel => $self->{LogLevel},
42 timeformat => "%Y/%m/%d %H:%M:%S",
43 message_layout => "[%T] %L %p %m",
44
45 filename => $self->{LogFile},
46 filelock => 1,
47 fileopen => 1,
48 reopen => 1,
49 utf8 => 1,
50 autoflush => 1,
51 },
52 2 ▶ ) unless $self->{DevNull};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DevNull"} 1 1 2
53
54 2 return $logger
55 }
56  
57 4 ▶sub logger {
Subroutine logger: called CC=2 SCAR=6.9
Pod undocumented
58 4 my ($self, $logger) = @_;
59 ## Return/set our Log::Handler
60 4 ▶ return $self->{LogObj} = $logger if blessed $logger;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($logger) 2 2 4
61 return $self->{LogObj}
62 2 }
63  
64 0 ▶sub log_to {
Subroutine log_to: not called CC=2 SCAR=17.9
Pod undocumented
65 ## Adjust the log destination
66 0 my ($self, $path) = @_;
67 0 ▶ return unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 0 0
68 0 $self->{LogFile} = $path;
69 0 $self->logger->flush;
70 0 $self->logger( $self->_create_logger );
71 0 return $self->logger
72 }
73  
74 1 1;
75 __END__
« lib/IRC/Indexer/Report/Network.pm ↑ Summary script/ircindexer-single »