Su/Log.pm

filter: Statementstmt 45.0% 162 / 360 Branchbran 31.2% 75 / 240 Conditioncond 25.0% 21 / 84 MC/DCmcdc 3.5% 2 / 56 Subroutinesub 44.6% 25 / 56 Podpod 100% 42 / 42 totaltotal 39.0% 327 / 838 CC 149 SCAR 26.0
CC
149
Cov
38%
log
42.0
log
42.0
off
23.3
CRAP 13.5
« Su/Process.pm ↑ Summary Su/Procs/ResourceProc.pm »
1 package Su::Log;
2 26 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 26 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =pod
7  
8 =head1 NAME
9  
10 Su::Log - A simple Logger which filters output by log level and regexp of the target class name.
11  
12 =head1 SYNOPSYS
13  
14 my $log = Su::Log->new;
15 $log->info("info message.");
16  
17 # Set the log level to output.
18 Su::Log->set_level("trace");
19 $log->trace("trace message.");
20  
21 # Disable logging and nothing output.
22 $log->off(__PACKAGE__);
23 $log->info("info message.");
24  
25 # Clear the logging state.
26 $log->clear(__PACKAGE__);
27  
28 # Enable logging.
29 $log->on(__PACKAGE__);
30 $log->info("info message.");
31  
32 # Clear the logging state.
33 $log->clear(__PACKAGE__);
34  
35 # Set the logging target and log level.
36 $log->on( 'Pkg::LogTarget', 'error' );
37  
38 # Set the logging target by regex.
39 $log->on( qr/Pkg::.*/, 'error' );
40  
41 # Clear the logging state.
42 $log->clear(qr/Pkg::.*/);
43  
44 # Output logs to the file.
45 $log->log_handler('path/to/logfile');
46  
47 =head1 DESCRIPTION
48  
49 Su::Log is a simple Logger module.
50 Su::Log has the following features.
51  
52 =over
53  
54 =item Narrow down the output by log level.
55  
56 =item Narrow down the logging target class.
57  
58 =item Narrow down the output by customized log kind.
59  
60 =item Customize the log handler function.
61  
62 =back
63  
64 =head1 FUNCTIONS
65  
66 =over
67  
68 =cut
69  
70 # Each elements consist of { class => $class, level => $level }
71 26 our @target_class = ();
72 26 our @target_tag = ();
73  
74 # Default log level.
75 26 our $level = "info";
76  
77 # User specified global log level.
78 26 our $global_log_level;
79  
80 # Elements are String or Regexp of the target class.
81 26 our @exclusion_class = ();
82  
83 # If you want to use this Log class not as oblect oriented style, but
84 # as function style directly, set current class name to this variable.
85 26 our $class_name;
86  
87 26 our $all_on = 0;
88 26 our $all_off = 0;
89 26 our $log_handler;
90  
91 BEGIN: {
92  
93 # Set default handler.
94 26 $log_handler =
95 37 ▶ sub { my $msg = _make_log_string(@_); print $msg; return $msg; };
Subroutine __ANON__: called CC=1 SCAR=0.0
96  
97 } ## end BEGIN:
98  
99 26 my $level_hash = {
100 debug => 0,
101 trace => 1,
102 info => 2,
103 warn => 3,
104 error => 4,
105 crit => 5,
106 };
107  
108 =item on()
109  
110 Add the passed module name to the list of the logging tareget.
111 If the parameter is not passed, then set the whole class as logging
112 target.
113  
114 =cut
115  
116 # NOTE: @target_class is a package variable, so shared with other
117 # logger even if you call this method via the specific logger
118 # instance.
119 9 ▶sub on {
Subroutine on: called CC=6 SCAR=26.1
Pod documented
120 0 ▶ my $self = shift if ( $_[0] eq __PACKAGE__ || ref $_[0] eq __PACKAGE__ );
Subroutine on: not called CC=6 SCAR=26.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__ 9 0 9
if $_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__ 0 0 0
Condition33%2/6
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
l!l&&r!l&&!r
450
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__ ref $_[0] eq __PACKAGE__
MC/DC0%0/2
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__ ref $_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= $_[0] eq __PACKAGE__B= ref $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $_[0] eq __PACKAGE__B= ref $_[0] eq __PACKAGE__
ABresult
1X1
011
000
121 0 my $class = shift;
122 0 my $level = shift;
123  
124 0 ▶ if ($class) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class) { } 9 0 9
if ($class) { } 0 0 0
125  
126 # diag( "on|" . $class . "|" . $level );
127  
128 # Remove old entry before adding new one.
129 0 ▶ if ( grep { $_->{class} =~ /^$class$/ } @target_class ) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$_->{"class"} =~ /^$class$/;} @target_class) 1 8 9
if (grep {$_->{"class"} =~ /^$class$/;} @target_class) 0 0 0
130  
131 # @target_class = grep { $_->{class} ne /^$class$/ } @target_class;
132 0 @target_class = grep { $_->{class} !~ /^$class$/ } @target_class;
133 }
134  
135 0 push @target_class, { class => $class, level => $level };
136  
137 0 my $bRegex = ref $class eq 'Regexp';
138 0 ▶ if ($bRegex) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bRegex) { } 1 8 9
if ($bRegex) { } 0 0 0
139 0 @exclusion_class = grep { $_ ne $class } @exclusion_class;
140 } else {
141 0 @exclusion_class = grep !/^$class$/, @exclusion_class;
142 }
143  
144 } else {
145 0 $self->{on} = 1;
146 }
147 } ## end sub on
148  
149 =item enable()
150  
151 This method force enable the logging regardless of whether the logging
152 of the target class is enabled or disabled.
153  
154 Internally, this method set the $all_on flag on, and $all_off flag
155 off. To clear this state, call the method L<Su::clear_all_flags>.
156  
157 =cut
158  
159 2 ▶sub enable {
Subroutine enable: called CC=1 SCAR=1.2
Pod documented
160 0 ▶ $all_on = 1;
Subroutine enable: not called CC=1 SCAR=1.2
Pod documented
161 0 $all_off = 0;
162 }
163  
164 =item off()
165  
166 Disable the logging of the class which name is passed as a parameter.
167  
168 $log->off('Target::Class');
169  
170 If the parameter is omitted, this effects only own instance.
171  
172 $log->off;
173  
174 =cut
175  
176 13 ▶sub off {
Subroutine off: called CC=8 SCAR=31.5
Pod documented
177 0 ▶ my $self = shift if ( $_[0] eq __PACKAGE__ || ref $_[0] eq __PACKAGE__ );
Subroutine off: not called CC=8 SCAR=31.5
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__ 13 0 13
if $_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__ 0 0 0
Condition33%2/6
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
l!l&&r!l&&!r
2110
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__ ref $_[0] eq __PACKAGE__
MC/DC0%0/2
$_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__
$_[0] eq __PACKAGE__ ref $_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= $_[0] eq __PACKAGE__B= ref $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $_[0] eq __PACKAGE__B= ref $_[0] eq __PACKAGE__
ABresult
1X1
011
000
178 0 my $class = shift;
179  
180 # In case of specified the log target.
181 0 ▶ if ($class) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class) { } 4 9 13
if ($class) { } 0 0 0
182  
183 # String parameter.
184 0 ▶ if ( !ref $class ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not ref $class) { } 3 1 4
elsif (ref $class eq 'Regexp') { } 1 0 1
if (not ref $class) { } 0 0 0
elsif (ref $class eq 'Regexp') { } 0 0 0
185 0 ▶ unless ( grep /^$class$/, @exclusion_class ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (grep /^$class$/, @exclusion_class) 3 0 3
unless (grep /^$class$/, @exclusion_class) 0 0 0
186 0 push @exclusion_class, $class;
187 }
188  
189 # Remove the passed class name from log target classes.
190 0 @target_class = grep { $_->{class} !~ /^$class$/ } @target_class;
191 } ## end if ( !ref $class )
192 elsif ( ref $class eq 'Regexp' ) {
193  
194 0 ▶ unless ( grep { $_ eq $class } @exclusion_class ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (grep {$_ eq $class;} @exclusion_class) 1 0 1
unless (grep {$_ eq $class;} @exclusion_class) 0 0 0
195 0 push @exclusion_class, $class;
196 }
197  
198 # Remove the passed regex from the log tareget classes.
199 0 @target_class = grep { $class ne $_->{class} } @target_class;
200 } ## end elsif ( ref $class eq 'Regexp')
201 } ## end if ($class)
202 else {
203  
204 # diag("off the logging of this instance.");
205  
206 # Instance parameter effects only own instance.
207 0 $self->{on} = undef;
208 } ## end else [ if ($class) ]
209 } ## end sub off
210  
211 =item disable()
212  
213 This method force disable the logging regardless of whether the logging
214 of the target class is enabled or disabled.
215  
216 Internally, ths method set the $all_off flag on, and $all_on flag off.
217 To clear this state, call the method L<Su::clear_all_flags>.
218  
219 =cut
220  
221 1 ▶sub disable {
Subroutine disable: called CC=1 SCAR=1.2
Pod documented
222  
223 0 ▶ $all_off = 1;
Subroutine disable: not called CC=1 SCAR=1.2
Pod documented
224 0 $all_on = 0;
225  
226 } ## end sub disable
227  
228 =item clear_all_flags()
229  
230 Clear C<$all_on> and C<$all_off> flags that is set by L<Su::enable>
231 or L<Su::disable> method.
232  
233 =cut
234  
235 8 ▶sub clear_all_flags {
Subroutine clear_all_flags: called CC=1 SCAR=1.2
Pod documented
236 0 ▶ $all_on = 0;
Subroutine clear_all_flags: not called CC=1 SCAR=1.2
Pod documented
237 0 $all_off = 0;
238 }
239  
240 =item clear()
241  
242 If the parameter is passed, This method clear the state of the passed
243 target that is set by the method L<on> and L<off>.
244  
245 If the parameter is omitted, then clear all of the log settings.
246  
247 =cut
248  
249 7 ▶sub clear {
Subroutine clear: called CC=5 SCAR=21.9
Pod documented
250 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine clear: not called CC=5 SCAR=21.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 7 0 7
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition33%2/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
610
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
251 0 my $class = shift;
252  
253 # Remove the specified expression.
254 0 ▶ if ($class) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class) { } 3 4 7
if ($class) { } 0 0 0
255 0 my $bRegex = ref $class eq 'Regexp';
256 0 ▶ if ($bRegex) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bRegex) { } 2 1 3
if ($bRegex) { } 0 0 0
257 0 @target_class = grep { $class ne $_->{class} } @target_class;
258 0 @exclusion_class = grep { $_ ne $class } @exclusion_class;
259 } else {
260 0 @target_class = grep { $_->{class} !~ /^$class$/ } @target_class;
261 0 @exclusion_class = grep !/^$class$/, @exclusion_class;
262 }
263  
264 } else {
265  
266 # Clear all condition.
267 0 @target_class = ();
268 0 @target_tag = ();
269 0 @exclusion_class = ();
270 0 clear_all_flags();
271 } ## end else [ if ($class) ]
272 } ## end sub clear
273  
274 =item tag_on()
275  
276 Add the passed tag to the target tags list.
277  
278 =cut
279  
280 0 ▶sub tag_on {
Subroutine tag_on: not called CC=2 SCAR=17.9
Pod documented
281 0 ▶ shift if ( $_[0] eq __PACKAGE__ );
Subroutine tag_on: not called CC=2 SCAR=17.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $_[0] eq __PACKAGE__ 0 0 0
if $_[0] eq __PACKAGE__ 0 0 0
282 0 my $tag = shift;
283 0 push @target_tag, $tag;
284 }
285  
286 =item tag_off()
287  
288 Remove the passed tag from the target tags list.
289  
290 =cut
291  
292 0 ▶sub tag_off {
Subroutine tag_off: not called CC=2 SCAR=17.9
Pod documented
293 0 ▶ shift if ( $_[0] eq __PACKAGE__ );
Subroutine tag_off: not called CC=2 SCAR=17.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $_[0] eq __PACKAGE__ 0 0 0
if $_[0] eq __PACKAGE__ 0 0 0
294 0 my $tag = shift;
295 0 @target_tag = grep !/^$tag$/, @target_tag;
296 }
297  
298 =item new()
299  
300 Constructor.
301  
302 my $log = new Su::Log->new;
303 my $log = new Su::Log->new($self);
304 my $log = new Su::Log->new('PKG::TargetClass');
305  
306 Instantiate the Logger class. The passed instance or the string of the
307 module name is registered as a logging target class. If the parameter
308 is omitted, then the caller is registered automatically.
309  
310 =cut
311  
312 163 ▶sub new {
Subroutine new: called CC=4 SCAR=17.9
Pod documented
313 0 ▶ my $self = shift;
Subroutine new: not called CC=4 SCAR=17.9
Pod documented
314 0 ▶ $self = ref $self if ( ref $self );
Branch: 2 branches
BranchTrueFalseTotal
if ref $self 1 162 163
if ref $self 0 0 0
315 0 my $target_class = shift;
316  
317 # If passed argment is a reference of the instance, then extract class name.
318 0 my $class_name = ref $target_class;
319  
320 # Else, use passed string as class name.
321 0 ▶ if ( !$class_name ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($class_name) 152 11 163
unless ($class_name) 0 0 0
322 0 $class_name = $target_class;
323 }
324  
325 0 ▶ if ( !$class_name ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($class_name) 152 11 163
unless ($class_name) 0 0 0
326 0 $class_name = caller();
327 }
328  
329 # diag("classname:" . $class_name);
330 # diag( Dumper($class_name));
331 # Su::Log->trace( "classname:" . $class_name );
332 # Su::Log->trace( Dumper($class_name) );
333  
334 # Add the caller class to the target list automatically.
335  
336 0 return bless { class_name => $class_name, on => 1, level => $level }, $self;
337 } ## end sub new
338  
339 =item is_target()
340  
341 Determine whether the module is a logging target or not.
342  
343 =cut
344  
345 2537 ▶sub is_target {
Subroutine is_target: called CC=9 SCAR=30.0
Pod documented
346 0 ▶ my $self = shift;
Subroutine is_target: not called CC=9 SCAR=30.0
Pod documented
347  
348 0 ▶ if ($all_on) {
Branch: 4 branches
BranchTrueFalseTotal
if ($all_on) { } 3 2534 2537
elsif ($all_off) { } 4 2530 2534
if ($all_on) { } 0 0 0
elsif ($all_off) { } 0 0 0
349  
350 0 return { is_target => 1, has_level => undef };
351 } elsif ($all_off) {
352  
353 0 return { is_target => 0, has_level => undef };
354 }
355  
356 0 my $self_class_name = $self;
357 0 ▶ if ( ref $self ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self) 81 2449 2530
if (ref $self) 0 0 0
358 0 ▶ $self_class_name = $self->{class_name} ? $self->{class_name} : $class_name;
Branch: 2 branches
BranchTrueFalseTotal
$self->{'class_name'} ? : 81 0 81
$self->{'class_name'} ? : 0 0 0
359 }
360  
361 #diag("check classname:" . $self->{class_name});
362 # if(! defined($self->{class_name})){
363 # die "Class name not passed to the log instance.";
364 # }
365  
366 #NOTE:Can not trace via trace or something Log class provide. Because recurssion occurs.
367 #diag( @target_class);
368  
369 # diag("grep result:" . (grep /^$self->{class_name}$/, @target_class));
370 # if (index($self->{class_name}, @target_class) != -1){
371 # diag( "exc cls:" . Dumper(@exclusion_class) );
372 0 ▶ if (
Branch: 4 branches
BranchTrueFalseTotal
if (grep {ref $_ eq 'Regexp' ? $self_class_name =~ /$_/ : $self_class_name =~ /^$_$/;} @exclusion_class) { } 6 2524 2530
elsif (my(@info) = grep({my $bRegex = ref $_->{'class'} eq 'Regexp'; if ($bRegex) { $self_class_name =~ /$_->{'class'}/; } else { $self_class_name =~ /^$_->{'class'}$/; } ;} @target_class)) { } 24 2500 2524
if (grep {ref $_ eq 'Regexp' ? $self_class_name =~ /$_/ : $self_class_name =~ /^$_$/;} @exclusion_class) { } 0 0 0
elsif (my(@info) = grep({my $bRegex = ref $_->{'class'} eq 'Regexp'; if ($bRegex) { $self_class_name =~ /$_->{'class'}/; } else { $self_class_name =~ /^$_->{'class'}$/; } ;} @target_class)) { } 0 0 0
373 grep {
374 0 ▶ ref $_ eq 'Regexp'
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'Regexp' ? : 2 6 8
ref $_ eq 'Regexp' ? : 0 0 0
375 ? $self_class_name =~ /$_/
376 : $self_class_name =~ /^$_$/
377 } @exclusion_class
378 )
379 {
380 0 return 0;
381 } elsif (
382 my @info =
383 grep {
384 0 my $bRegex = ref $_->{class} eq 'Regexp';
385 0 ▶ if ($bRegex) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bRegex) { } 1 46 47
if ($bRegex) { } 0 0 0
386  
387 # diag('use regex');
388  
389 # Use class field as regexp.
390 0 $self_class_name =~ /$_->{class}/;
391 } else {
392  
393 # diag('use str');
394  
395 # Use class field as string,directly.
396 0 $self_class_name =~ /^$_->{class}$/;
397 } ## end else [ if ($bRegex) ]
398 } @target_class
399 )
400 {
401  
402 # diag( Dumper(@target_class) );
403 # diag("here2:$info[0]->{class} --- $info[0]->{level}");
404 0 return { is_target => 1, has_level => 1, level => $info[0]->{level} };
405 } else {
406  
407 # diag( "here3:" . $self . $self->{on} );
408  
409 # Return the instance flag.
410 # return $self->{on};
411 0 return { is_target => $self->{on}, has_level => undef };
412 } ## end else [ if ($bRegex) ]
413 } ## end sub is_target
414  
415 =item set_level()
416  
417 Su::Log->set_level("trace");
418  
419 Set the log level which effects instance scope. Default level is B<info>;
420  
421 =cut
422  
423 2 ▶sub set_level {
Subroutine set_level: called CC=4 SCAR=21.7
Pod documented
424  
425 # The first argment may be reference of object or string of class name.
426 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine set_level: not called CC=4 SCAR=21.7
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 2 0 2
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
200
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
427 0 my $passed_level = shift;
428 croak "Passed log level is invalid:" . $passed_level
429 0 ▶ if !grep /^$passed_level$/, keys %{$level_hash};
Branch: 2 branches
BranchTrueFalseTotal
unless grep /^$passed_level$/, keys %{$level_hash;} 0 2 2
unless grep /^$passed_level$/, keys %{$level_hash;} 0 0 0
430 0 $self->{level} = $passed_level;
431  
432 } ## end sub set_level
433  
434 =item set_global_log_level()
435  
436 Su::Log->set_default_log_level("trace");
437  
438 Set the log level. This setting effects as the package scope variable.
439  
440 To clear the $global_log_level flag, pass undef to this method.
441  
442 =cut
443  
444 5 ▶sub set_global_log_level {
Subroutine set_global_log_level: called CC=5 SCAR=24.3
Pod documented
445  
446 # The first argment may be reference of object or string of class name.
447 0 ▶ shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine set_global_log_level: not called CC=5 SCAR=24.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 5 0 5
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition33%2/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
320
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
448 0 my $passed_level = shift;
449 croak "Passed log level is invalid:" . $passed_level
450 0 ▶ if defined $passed_level && !grep /^$passed_level$/, keys %{$level_hash};
Branch: 2 branches
BranchTrueFalseTotal
if defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;}) 0 5 5
if defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;}) 0 0 0
Condition33%2/6
defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;})
!ll&&!rl&&r
230
defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;})
defined $passed_level not grep(/^$passed_level$/, keys %{$level_hash;})
MC/DC0%0/2
defined $passed_level and not grep(/^$passed_level$/, keys %{$level_hash;})
defined $passed_level not grep(/^$passed_level$/, keys %{$level_hash;})
Truth table66%2/3
A and not(B)
A= defined $passed_levelB= not grep(/^$passed_level$/, keys %{$level_hash;})
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $passed_levelB= not grep(/^$passed_level$/, keys %{$level_hash;})
ABresult
0X0
100
111
451 0 $global_log_level = $passed_level;
452 } ## end sub set_global_log_level
453  
454 =item is_large_level()
455  
456 Return whether the passed log level is larger than the current log level or not.
457 If the second parameter is passed, then compare that value as the current log level.
458  
459 =cut
460  
461 73 ▶sub is_large_level {
Subroutine is_large_level: called CC=7 SCAR=28.4
Pod documented
462 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ );
Subroutine is_large_level: not called CC=7 SCAR=28.4
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ 73 0 73
if ref $_[0] eq __PACKAGE__ 0 0 0
463 0 ▶ $self = caller() unless $self;
Branch: 2 branches
BranchTrueFalseTotal
unless $self 0 73 73
unless $self 0 0 0
464  
465 # diag "dumper:" . Dumper( $self->{class_name} );
466 0 my $arg = shift;
467  
468 #NOTE:Can not trace via trace command which Log class provides, because recursion occurs.
469 #diag("compare:" . $arg . ":" . $level);
470  
471 0 my $compare_target_level = shift;
472  
473 # If the second parameter is passed, use it as compare target directly.
474 0 ▶ unless ($compare_target_level) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($compare_target_level) 64 9 73
unless ($compare_target_level) 0 0 0
475 0 ▶ if ( defined $global_log_level ) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $global_log_level) { } 3 61 64
elsif ($self->{'level'}) { } 61 0 61
if (defined $global_log_level) { } 0 0 0
elsif ($self->{'level'}) { } 0 0 0
476 0 $compare_target_level = $global_log_level;
477 } elsif ( $self->{level} ) {
478 0 $compare_target_level = $self->{level};
479 } else {
480 0 $compare_target_level = $level;
481 }
482 } ## end unless ($compare_target_level)
483  
484 # diag "[TRACE]compare_target_level:$compare_target_level:arg:$arg\n";
485 0 ▶ return $level_hash->{$arg} >= $level_hash->{$compare_target_level} ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$level_hash->{$arg} >= $level_hash->{$compare_target_level} ? : 38 35 73
$level_hash->{$arg} >= $level_hash->{$compare_target_level} ? : 0 0 0
486 } ## end sub is_large_level
487  
488 2537 ▶sub _log_method_impl {
Subroutine _log_method_impl: called CC=6 SCAR=23.5
489 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ );
Subroutine _log_method_impl: not called CC=6 SCAR=23.5
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ 88 2449 2537
if ref $_[0] eq __PACKAGE__ 0 0 0
490 0 my $opt_href = shift;
491 0 my $caller_prefix = $opt_href->{caller};
492 0 my $method_level = $opt_href->{level};
493 0 ▶ my $log_handler = $self->{log_handler} ? $self->{log_handler} : $log_handler;
Branch: 2 branches
BranchTrueFalseTotal
$self->{'log_handler'} ? : 1 2536 2537
$self->{'log_handler'} ? : 0 0 0
494 0 ▶ my $target_info = is_target( _is_empty($self) ? caller() : $self );
Branch: 2 branches
BranchTrueFalseTotal
_is_empty($self) ? : 2449 88 2537
_is_empty($self) ? : 0 0 0
495  
496 0 ▶ if ( $target_info->{is_target}
Branch: 2 branches
BranchTrueFalseTotal
if ($target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})) 38 2499 2537
if ($target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})) 0 0 0
Condition50%3/6
$target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})
!ll&&!rl&&r
24643538
$target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})
!ll&&!rl&&r
000
MC/DC100%2/2
$target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})
$target_info->{"is_target"} $self->is_large_level($method_level, $target_info->{"level"})
MC/DC0%0/2
$target_info->{"is_target"} and $self->is_large_level($method_level, $target_info->{"level"})
$target_info->{"is_target"} $self->is_large_level($method_level, $target_info->{"level"})
Truth table100%3/3
A and B
A= $target_info->{"is_target"}B= $self->is_large_level($method_level, $target_info->{"level"})
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $target_info->{"is_target"}B= $self->is_large_level($method_level, $target_info->{"level"})
ABresult
0X0
100
111
497 && $self->is_large_level( $method_level, $target_info->{level} ) )
498 {
499 0 return $log_handler->( "[$caller_prefix]", uc("[$method_level]"), @_ );
500 }
501 } ## end sub _log_method_impl
502  
503 =item trace()
504  
505 Log the passed message as trace level.
506  
507 =cut
508  
509 2480 ▶sub trace {
Subroutine trace: called CC=3 SCAR=16.2
Pod documented
510 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine trace: not called CC=3 SCAR=16.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 2480 0 2480
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition33%2/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
3124490
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table66%2/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
511  
512 0 my ( $pkg, $file, $line ) = caller;
513  
514 0 my $caller_prefix = $file . ':L' . $line;
515 0 $self->_log_method_impl( { caller => $caller_prefix, level => "trace" }, @_ );
516 } ## end sub trace
517  
518 =item info()
519  
520 Log the passed message as info level.
521  
522 =cut
523  
524 42 ▶sub info {
Subroutine info: called CC=3 SCAR=17.3
Pod documented
525 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine info: not called CC=3 SCAR=17.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 42 0 42
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
4200
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
526  
527 0 my ( $pkg, $file, $line ) = caller;
528  
529 0 my $caller_prefix = $file . ':L' . $line;
530 0 $self->_log_method_impl( { caller => $caller_prefix, level => "info" }, @_ );
531 } ## end sub info
532  
533 =item warn()
534  
535 Log the passed message as warn level.
536  
537 =cut
538  
539 3 ▶sub warn {
Subroutine warn: called CC=3 SCAR=17.3
Pod documented
540 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine warn: not called CC=3 SCAR=17.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 3 0 3
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
300
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
541 0 my ( $pkg, $file, $line ) = caller;
542 0 my $caller_prefix = $file . ':L' . $line;
543 0 $self->_log_method_impl( { caller => $caller_prefix, level => "warn" }, @_ );
544 } ## end sub warn
545  
546 =item error()
547  
548 Log the passed message as error level.
549  
550 =cut
551  
552 4 ▶sub error {
Subroutine error: called CC=3 SCAR=17.3
Pod documented
553 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine error: not called CC=3 SCAR=17.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 4 0 4
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
400
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
554 0 my ( $pkg, $file, $line ) = caller;
555 0 my $caller_prefix = $file . ':L' . $line;
556 0 $self->_log_method_impl( { caller => $caller_prefix, level => "error" }, @_ );
557 } ## end sub error
558  
559 =item crit()
560  
561 Log the passed message as crit level.
562  
563 =cut
564  
565 4 ▶sub crit {
Subroutine crit: called CC=3 SCAR=17.3
Pod documented
566 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine crit: not called CC=3 SCAR=17.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 4 0 4
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
400
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
567 0 my ( $pkg, $file, $line ) = caller;
568 0 my $caller_prefix = $file . ':L' . $line;
569 0 $self->_log_method_impl( { caller => $caller_prefix, level => "crit" }, @_ );
570 } ## end sub crit
571  
572 =item debug()
573  
574 Log the passed message as debug level.
575  
576 =cut
577  
578 4 ▶sub debug {
Subroutine debug: called CC=3 SCAR=17.3
Pod documented
579 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ || $_[0] eq __PACKAGE__ );
Subroutine debug: not called CC=3 SCAR=17.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 4 0 4
if ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__ 0 0 0
Condition16%1/6
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
400
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
MC/DC0%0/2
ref $_[0] eq __PACKAGE__ or $_[0] eq __PACKAGE__
ref $_[0] eq __PACKAGE__ $_[0] eq __PACKAGE__
Truth table33%1/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= ref $_[0] eq __PACKAGE__B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
580 0 my ( $pkg, $file, $line ) = caller;
581 0 my $caller_prefix = $file . ':L' . $line;
582 0 $self->_log_method_impl( { caller => $caller_prefix, level => "debug" }, @_ );
583  
584 } ## end sub debug
585  
586 =item log()
587  
588 Log the message with the passed tag, if the passed tag is active.
589  
590 my $log = Su::Log->new($self);
591 $log->log("some_tag","some message");
592  
593 =cut
594  
595 0 ▶sub log {
Subroutine log: not called CC=6 SCAR=37.4
Pod documented
596 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ );
Subroutine log: not called CC=6 SCAR=37.4
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ 0 0 0
if ref $_[0] eq __PACKAGE__ 0 0 0
597 0 my $tag = shift;
598  
599 0 ▶ my $log_handler = $self->{log_handler} ? $self->{log_handler} : $log_handler;
Branch: 2 branches
BranchTrueFalseTotal
$self->{'log_handler'} ? : 0 0 0
$self->{'log_handler'} ? : 0 0 0
600 0 ▶ if ( is_target( _is_empty($self) ? caller() : $self )
Branch: 4 branches
BranchTrueFalseTotal
if (is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag) 0 0 0
_is_empty($self) ? : 0 0 0
if (is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag) 0 0 0
_is_empty($self) ? : 0 0 0
Condition0%0/6
is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag
!ll&&!rl&&r
000
is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag
!ll&&!rl&&r
000
MC/DC0%0/2
is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag
is_target(_is_empty($self) ? caller() : $self) grep /^$tag$/, @target_tag
MC/DC0%0/2
is_target(_is_empty($self) ? caller() : $self) and grep /^$tag$/, @target_tag
is_target(_is_empty($self) ? caller() : $self) grep /^$tag$/, @target_tag
Truth table0%0/3
A and B
A= is_target(_is_empty($self) ? caller() : $self)B= grep /^$tag$/, @target_tag
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= is_target(_is_empty($self) ? caller() : $self)B= grep /^$tag$/, @target_tag
ABresult
0X0
100
111
601 && ( grep /^$tag$/, @target_tag ) )
602 {
603 0 my ( $pkg, $file, $line ) = caller;
604 0 my $caller_prefix = $file . ':L' . $line;
605 0 return $log_handler->( "[$caller_prefix]", "[$tag]", @_ );
606 } ## end if ( is_target( _is_empty...))
607  
608 } ## end sub log
609  
610 =item log_handler()
611  
612 Set the passed method as the log handler of L<Su::Log|Su::Log>.
613  
614 $log->log_handler(\&hndl);
615 $log->info("info message");
616  
617 sub hndl{
618 print(join 'custom log handler:', @_);
619 }
620  
621 $log->log_handler(
622 sub {
623 my $level = shift;
624 my $msg = @_;
625 print $F $level . join( ' ', @_ ) . "\n";
626 }
627 );
628  
629 If the passed parameter is string, then automatically the handler is
630 set to output log to the passed file name.
631  
632 =cut
633  
634 1 ▶sub log_handler {
Subroutine log_handler: called CC=6 SCAR=30.9
Pod documented
635 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ );
Subroutine log_handler: not called CC=6 SCAR=30.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ 1 0 1
if ref $_[0] eq __PACKAGE__ 0 0 0
636 0 my $handler = shift;
637  
638 # Work as setter method.
639 0 ▶ if ($handler) {
Branch: 2 branches
BranchTrueFalseTotal
if ($handler) { } 1 0 1
if ($handler) { } 0 0 0
640 0 ▶ if ($self) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self) { } 1 0 1
if ($self) { } 0 0 0
641 0 ▶ if ( ref $handler eq 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $handler eq 'CODE') { } 1 0 1
if (ref $handler eq 'CODE') { } 0 0 0
642 0 $self->{log_handler} = $handler;
643 } else {
644  
645 # $handler is passed as log file name.
646 0 $self->{log_handler} = _make_default_log_file_handler($handler);
647 }
648 } else {
649  
650 # $log_handler = $handler;
651 0 ▶ if ( ref $handler eq 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $handler eq 'CODE') { } 0 0 0
if (ref $handler eq 'CODE') { } 0 0 0
652 0 $log_handler = $handler;
653 } else {
654  
655 # $handler is passed as log file name.
656 0 $log_handler = _make_default_log_file_handler($handler);
657 }
658  
659 } ## end else [ if ($self) ]
660 } else {
661  
662 # The param is omitted, just work as a getter method.
663 0 return $log_handler;
664 }
665 } ## end sub log_handler
666  
667 =begin comment
668  
669 Return the handler to output log to the log file. Passed parameter is
670 a log file name.
671  
672 =end comment
673  
674 =cut
675  
676 0 ▶sub _make_default_log_file_handler {
Subroutine _make_default_log_file_handler: not called CC=3 SCAR=24.8
677 0 ▶ my $self = shift if ( ref $_[0] eq __PACKAGE__ );
Subroutine _make_default_log_file_handler: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
if ref $_[0] eq __PACKAGE__ 0 0 0
if ref $_[0] eq __PACKAGE__ 0 0 0
678 0 my $log_file_name = shift;
679 0 ▶ open( my $F, '>>', $log_file_name ) or die $!;
Branch: 2 branches
BranchTrueFalseTotal
open my $F, ">>", $log_file_name or die $! 0 0 0
open my $F, ">>", $log_file_name or die $! 0 0 0
680 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
681 0 ▶ my $level = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
682 0 my $msg = _make_log_string(@_);
683 0 print $F $level . $msg;
684 0 };
685 } ## end sub _make_default_log_file_handler
686  
687 =begin comment
688  
689 Internal Utility function.
690  
691 =end comment
692  
693 =cut
694  
695 2537 ▶sub _is_empty {
Subroutine _is_empty: called CC=4 SCAR=19.7
696 0 ▶ my $arg = shift;
Subroutine _is_empty: not called CC=4 SCAR=19.7
697 0 ▶ return 1 if ( !$arg );
Branch: 2 branches
BranchTrueFalseTotal
unless $arg 0 2537 2537
unless $arg 0 0 0
698 0 ▶ if ( ref $arg eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq "HASH") 2449 88 2537
if (ref $arg eq "HASH") 0 0 0
699 0 ▶ return 1 unless ( scalar keys %{$arg} );
Branch: 2 branches
BranchTrueFalseTotal
unless scalar keys %{$arg;} 2449 0 2449
unless scalar keys %{$arg;} 0 0 0
700 }
701 0 return 0;
702 } ## end sub _is_empty
703  
704 =begin comment
705  
706 Add the prefix of time to the passed parameter and return it as a string.
707 The caller information is passed to this method as a parameter.
708  
709 =end comment
710  
711 =cut
712  
713 37 ▶sub _make_log_string {
Subroutine _make_log_string: called CC=1 SCAR=1.2
714 0 ▶ my ( $s, $mi, $h, $d, $m, $y ) = ( localtime(time) )[ 0 .. 6 ];
Subroutine _make_log_string: not called CC=1 SCAR=1.2
715 0 my $date_prefix = sprintf "%04d/%02d/%02d %02d:%02d:%02d", $y + 1900, $m + 1,
716 $d,
717 $h, $mi, $s;
718  
719 0 return '[' . $date_prefix . ']' . join( '', @_, "\n" );
720 } ## end sub _make_log_string
721  
722 =pod
723  
724 =back
725  
726 =cut
727  
« Su/Process.pm ↑ Summary Su/Procs/ResourceProc.pm »