line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Minilla::Logger; |
2
|
61
|
|
|
61
|
|
476
|
use strict; |
|
61
|
|
|
|
|
147
|
|
|
61
|
|
|
|
|
1830
|
|
3
|
61
|
|
|
61
|
|
430
|
use warnings; |
|
61
|
|
|
|
|
130
|
|
|
61
|
|
|
|
|
1441
|
|
4
|
61
|
|
|
61
|
|
315
|
use utf8; |
|
61
|
|
|
|
|
143
|
|
|
61
|
|
|
|
|
326
|
|
5
|
61
|
|
|
61
|
|
1503
|
use parent qw(Exporter); |
|
61
|
|
|
|
|
120
|
|
|
61
|
|
|
|
|
381
|
|
6
|
|
|
|
|
|
|
|
7
|
61
|
|
|
61
|
|
42382
|
use Term::ANSIColor qw(colored); |
|
61
|
|
|
|
|
543069
|
|
|
61
|
|
|
|
|
98109
|
|
8
|
|
|
|
|
|
|
require Win32::Console::ANSI if $^O eq 'MSWin32'; |
9
|
|
|
|
|
|
|
|
10
|
61
|
|
|
61
|
|
23936
|
use Minilla::Errors; |
|
61
|
|
|
|
|
168
|
|
|
61
|
|
|
|
|
3755
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw(debugf infof warnf errorf); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $COLOR; |
15
|
|
|
|
|
|
|
|
16
|
61
|
|
|
61
|
|
432
|
use constant { DEBUG => 1, INFO => 2, WARN => 3, ERROR => 4 }; |
|
61
|
|
|
|
|
111
|
|
|
61
|
|
|
|
|
29193
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $Colors = { |
19
|
|
|
|
|
|
|
DEBUG, => 'green', |
20
|
|
|
|
|
|
|
WARN, => 'yellow', |
21
|
|
|
|
|
|
|
INFO, => 'cyan', |
22
|
|
|
|
|
|
|
ERROR, => 'red', |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _printf { |
26
|
0
|
|
|
0
|
|
|
my $type = pop; |
27
|
0
|
|
|
|
|
|
my($temp, @args) = @_; |
28
|
0
|
0
|
|
|
|
|
_print(sprintf($temp, map { defined($_) ? $_ : '-' } @args), $type); |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _print { |
32
|
0
|
|
|
0
|
|
|
my($msg, $type) = @_; |
33
|
0
|
0
|
0
|
|
|
|
return if $type == DEBUG && !Minilla->debug; |
34
|
0
|
0
|
0
|
|
|
|
$msg = colored $msg, $Colors->{$type} if defined $type && $COLOR; |
35
|
0
|
0
|
0
|
|
|
|
my $fh = $type && $type >= WARN ? *STDERR : *STDOUT; |
36
|
0
|
|
|
|
|
|
print {$fh} $msg; |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub infof { |
40
|
0
|
|
|
0
|
0
|
|
_printf(@_, INFO); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub warnf { |
44
|
0
|
|
|
0
|
0
|
|
_printf(@_, WARN); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub debugf { |
48
|
0
|
|
|
0
|
0
|
|
_printf(@_, DEBUG); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub errorf { |
52
|
0
|
|
|
0
|
0
|
|
my(@msg) = @_; |
53
|
0
|
|
|
|
|
|
_printf(@msg, ERROR); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $fmt = shift @msg; |
56
|
0
|
|
|
|
|
|
Minilla::Error::CommandExit->throw(sprintf($fmt, @msg)); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|