line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Minilla::Logger; |
2
|
61
|
|
|
61
|
|
404
|
use strict; |
|
61
|
|
|
|
|
121
|
|
|
61
|
|
|
|
|
1693
|
|
3
|
61
|
|
|
61
|
|
297
|
use warnings; |
|
61
|
|
|
|
|
182
|
|
|
61
|
|
|
|
|
1476
|
|
4
|
61
|
|
|
61
|
|
309
|
use utf8; |
|
61
|
|
|
|
|
141
|
|
|
61
|
|
|
|
|
317
|
|
5
|
61
|
|
|
61
|
|
1505
|
use parent qw(Exporter); |
|
61
|
|
|
|
|
146
|
|
|
61
|
|
|
|
|
330
|
|
6
|
|
|
|
|
|
|
|
7
|
61
|
|
|
61
|
|
42642
|
use Term::ANSIColor qw(colored); |
|
61
|
|
|
|
|
542124
|
|
|
61
|
|
|
|
|
101464
|
|
8
|
|
|
|
|
|
|
require Win32::Console::ANSI if $^O eq 'MSWin32'; |
9
|
|
|
|
|
|
|
|
10
|
61
|
|
|
61
|
|
24131
|
use Minilla::Errors; |
|
61
|
|
|
|
|
168
|
|
|
61
|
|
|
|
|
3720
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw(debugf infof warnf errorf); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $COLOR; |
15
|
|
|
|
|
|
|
|
16
|
61
|
|
|
61
|
|
410
|
use constant { DEBUG => 1, INFO => 2, WARN => 3, ERROR => 4 }; |
|
61
|
|
|
|
|
112
|
|
|
61
|
|
|
|
|
29153
|
|
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
|
|
|
|
|
|
|
|