Minilla/Logger.pm

filter: Statementstmt 100% 48 / 48 Branchbran 50.0% 4 / 8 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 15 / 15 Podpod 20.0% 1 / 5 totaltotal 80.9% 72 / 89 CC 7 SCAR 8.8
CC
7
Cov
88%
_print
6.1
slog
2.0
_printf
2.0
CRAP 2.4
« Minilla/Release/Tag.pm ↑ Summary Minilla/Release/RewriteChanges.pm »
1 package Minilla::Logger;
2 77 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 77 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 77 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 77 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 77 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 77 ▶use Term::ANSIColor qw(colored);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 77 ▶require Win32::Console::ANSI if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 77 77
10  
11 77 ▶use Minilla::Errors;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 77 our @EXPORT = qw(debugf infof warnf errorf slog);
14  
15 77 our $COLOR;
16 77 our $SLOG_OUTPUT;
17  
18 77 ▶use constant { DEBUG => 1, INFO => 2, WARN => 3, ERROR => 4 };
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 77 our $Colors = {
21 DEBUG, => 'green',
22 WARN, => 'yellow',
23 INFO, => 'cyan',
24 ERROR, => 'red',
25 };
26  
27 24 ▶sub _printf {
Subroutine _printf: called CC=2 SCAR=7.0
28 24 my $type = pop;
29 24 my($temp, @args) = @_;
30 24 ▶ _print(sprintf($temp, map { defined($_) ? $_ : '-' } @args), $type);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 9 0 9
31 }
32  
33 24 ▶sub _print {
Subroutine _print: called CC=5 SCAR=18.1
34 24 my($msg, $type) = @_;
35 24 ▶ return if $type == DEBUG && !Minilla->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $type == 1 and not "Minilla"->debug 0 24 24
Condition66%2/3
$type == 1 and not "Minilla"->debug
!ll&&!rl&&r
2310
MC/DC0%0/2
$type == 1 and not "Minilla"->debug
$type == 1 not "Minilla"->debug
Truth table66%2/3
A and not(B)
A= $type == 1B= not "Minilla"->debug
ABresult
0X0
100
111
36 24 ▶ $msg = colored $msg, $Colors->{$type} if defined $type && $COLOR;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and $Minilla::Logger::COLOR 0 24 24
Condition33%1/3
defined $type and $Minilla::Logger::COLOR
!ll&&!rl&&r
0240
MC/DC0%0/2
defined $type and $Minilla::Logger::COLOR
defined $type $Minilla::Logger::COLOR
Truth table33%1/3
A and B
A= defined $typeB= $Minilla::Logger::COLOR
ABresult
0X0
100
111
37 24 print STDERR $msg;
38 }
39  
40 12 ▶sub infof {
Subroutine infof: called CC=1 SCAR=0.0
Pod undocumented
41 12 _printf(@_, INFO);
42 }
43  
44 5 ▶sub warnf {
Subroutine warnf: called CC=1 SCAR=0.0
Pod undocumented
45 5 _printf(@_, WARN);
46 }
47  
48 1 ▶sub debugf {
Subroutine debugf: called CC=1 SCAR=0.0
Pod undocumented
49 1 _printf(@_, DEBUG);
50 }
51  
52 5 ▶sub slog {
Subroutine slog: called CC=2 SCAR=7.1
Pod documented
53 5 ▶ my $output = $SLOG_OUTPUT || \*STDOUT;
Condition50%1/2
$Minilla::Logger::SLOG_OUTPUT || \*STDOUT
l!l
05
MC/DC0%0/1
$Minilla::Logger::SLOG_OUTPUT || \*STDOUT
$Minilla::Logger::SLOG_OUTPUT
Truth table50%1/2
A
A= $Minilla::Logger::SLOG_OUTPUT
Aresult
11
00
54 5 print {$output} JSON::PP->new->ascii->encode(shift), "\n";
55 }
56  
57 6 ▶sub errorf {
Subroutine errorf: called CC=1 SCAR=0.0
Pod undocumented
58 6 my(@msg) = @_;
59 6 _printf(@msg, ERROR);
60  
61 6 my $fmt = shift @msg;
62 6 Minilla::Error::CommandExit->throw(sprintf($fmt, @msg));
63 }
64  
65 77 1;
66  
67 =head1 NAME
68  
69 Minilla::Logger - Minilla logging functions
70  
71 =head1 FUNCTIONS
72  
73 =head2 slog
74  
75 slog({ event => 'build', status => 'success' });
76  
77 Writes the supplied hash reference as a single JSON object followed by a
78 newline to standard output. Nested arrays and hashes are supported, and
79 undefined values become JSON null. Pass an empty hash reference to write an
80 empty object. JSON encoding errors propagate to the caller.
81  
82 Strings are escaped, including embedded newlines and non-ASCII characters,
83 so each call produces one physical line regardless of the output encoding.
84 Unlike the formatted logging functions, C<slog> always writes to standard
85 output and is not affected by color or debug settings.
86 During CLI execution, it uses the saved standard output handle while all
87 other output is redirected to standard error.
88  
89 =cut
« Minilla/Release/Tag.pm ↑ Summary Minilla/Release/RewriteChanges.pm »