line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::MirrorMerger::Logger; |
2
|
2
|
|
|
2
|
|
251020
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
57
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
474
|
use Class::Accessor::Lite ro => [qw/level/], new => 1; |
|
2
|
|
|
|
|
1272
|
|
|
2
|
|
|
|
|
15
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
792
|
use Data::Dumper (); |
|
2
|
|
|
|
|
7291
|
|
|
2
|
|
|
|
|
52
|
|
8
|
2
|
|
|
2
|
|
907
|
use Time::Moment; |
|
2
|
|
|
|
|
2826
|
|
|
2
|
|
|
|
|
795
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %LEVEL_MAP = ( |
11
|
|
|
|
|
|
|
error => 1000, |
12
|
|
|
|
|
|
|
warn => 500, |
13
|
|
|
|
|
|
|
info => 100, |
14
|
|
|
|
|
|
|
debug => 10, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
0
|
0
|
sub write_log { require Carp; Carp::croak('abstruct method') } |
|
0
|
|
|
|
|
0
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub format_log { |
20
|
6
|
|
|
6
|
0
|
17
|
my ($self, $now, $level, $msg, $attr) = @_; |
21
|
6
|
50
|
|
|
|
17
|
unless (defined $attr) { |
22
|
6
|
|
|
|
|
99
|
return sprintf '%s [%s] %s', $now->to_string(), uc $level, $msg; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
my $attr_str = do { |
26
|
0
|
|
|
|
|
0
|
local $Data::Dumper::Terse = 1; |
27
|
0
|
|
|
|
|
0
|
local $Data::Dumper::Indent = 0; |
28
|
0
|
|
|
|
|
0
|
local $Data::Dumper::Sortkeys = 1; |
29
|
0
|
|
|
|
|
0
|
Data::Dumper::Dumper($attr); |
30
|
|
|
|
|
|
|
}; |
31
|
0
|
|
|
|
|
0
|
return sprintf '%s [%s] %s (%s)', $now->to_string(), uc $level, $msg, $attr_str; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _log { |
35
|
18
|
|
|
18
|
|
41
|
my ($self, $level, $msg, $attr) = @_; |
36
|
18
|
100
|
|
|
|
57
|
return if $LEVEL_MAP{$level} < $LEVEL_MAP{$self->level}; |
37
|
|
|
|
|
|
|
|
38
|
6
|
|
|
|
|
90
|
my $now = Time::Moment->now_utc(); |
39
|
6
|
|
|
|
|
22
|
my $payload = $self->format_log($now, $level, $msg, $attr); |
40
|
6
|
|
|
|
|
22
|
$self->write_log($payload); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub error { |
44
|
0
|
|
|
0
|
0
|
0
|
my ($self, $msg, $attr) = @_; |
45
|
0
|
|
|
|
|
0
|
$self->_log(error => $msg, $attr); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub warn { |
49
|
0
|
|
|
0
|
0
|
0
|
my ($self, $msg, $attr) = @_; |
50
|
0
|
|
|
|
|
0
|
$self->_log(warn => $msg, $attr); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub info { |
54
|
6
|
|
|
6
|
0
|
101
|
my ($self, $msg, $attr) = @_; |
55
|
6
|
|
|
|
|
22
|
$self->_log(info => $msg, $attr); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub debug { |
59
|
12
|
|
|
12
|
0
|
1315
|
my ($self, $msg, $attr) = @_; |
60
|
12
|
|
|
|
|
36
|
$self->_log(debug => $msg, $attr); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |