line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Minilla::Logger; |
2
|
61
|
|
|
61
|
|
453
|
use strict; |
|
61
|
|
|
|
|
140
|
|
|
61
|
|
|
|
|
1728
|
|
3
|
61
|
|
|
61
|
|
295
|
use warnings; |
|
61
|
|
|
|
|
108
|
|
|
61
|
|
|
|
|
1406
|
|
4
|
61
|
|
|
61
|
|
298
|
use utf8; |
|
61
|
|
|
|
|
113
|
|
|
61
|
|
|
|
|
317
|
|
5
|
61
|
|
|
61
|
|
1509
|
use parent qw(Exporter); |
|
61
|
|
|
|
|
131
|
|
|
61
|
|
|
|
|
297
|
|
6
|
|
|
|
|
|
|
|
7
|
61
|
|
|
61
|
|
43380
|
use Term::ANSIColor qw(colored); |
|
61
|
|
|
|
|
545857
|
|
|
61
|
|
|
|
|
99387
|
|
8
|
|
|
|
|
|
|
require Win32::Console::ANSI if $^O eq 'MSWin32'; |
9
|
|
|
|
|
|
|
|
10
|
61
|
|
|
61
|
|
24552
|
use Minilla::Errors; |
|
61
|
|
|
|
|
189
|
|
|
61
|
|
|
|
|
3829
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw(debugf infof warnf errorf); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $COLOR; |
15
|
|
|
|
|
|
|
|
16
|
61
|
|
|
61
|
|
419
|
use constant { DEBUG => 1, INFO => 2, WARN => 3, ERROR => 4 }; |
|
61
|
|
|
|
|
114
|
|
|
61
|
|
|
|
|
29377
|
|
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
|
|
|
|
|
|
|
|