line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Mini::LoggerBase; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
59269
|
use strict; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
126
|
|
4
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
123
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
21
|
use Carp qw(croak); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
229
|
|
7
|
5
|
|
|
5
|
|
22
|
use List::Util qw(first); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
509
|
|
8
|
5
|
|
|
5
|
|
1939
|
use Time::Moment; |
|
5
|
|
|
|
|
6390
|
|
|
5
|
|
|
|
|
2121
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $LEVELS = { |
11
|
|
|
|
|
|
|
error => 1, |
12
|
|
|
|
|
|
|
warn => 2, |
13
|
|
|
|
|
|
|
info => 3, |
14
|
|
|
|
|
|
|
debug => 4, |
15
|
|
|
|
|
|
|
trace => 5 |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# say STDERR Dumper(\@_); |
21
|
30
|
|
|
30
|
0
|
24122
|
my $class = shift; |
22
|
30
|
|
|
|
|
57
|
my (%params) = @_; |
23
|
|
|
|
|
|
|
|
24
|
30
|
|
|
|
|
42
|
my $self = {}; |
25
|
30
|
|
|
|
|
39
|
bless $self, $class; |
26
|
|
|
|
|
|
|
|
27
|
30
|
|
100
|
|
|
147
|
$self->{'level'} = $params{'level'} || 'error'; |
28
|
|
|
|
|
|
|
|
29
|
30
|
|
|
|
|
72
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub set_level { |
33
|
28
|
|
|
28
|
0
|
2310
|
my $self = shift; |
34
|
28
|
|
|
|
|
40
|
my ($new_level) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
croak('Unknown log level') |
37
|
28
|
100
|
|
95
|
|
158
|
unless first { $new_level eq $_ } keys %$LEVELS; |
|
95
|
|
|
|
|
232
|
|
38
|
|
|
|
|
|
|
|
39
|
27
|
|
|
|
|
103
|
$self->{'level'} = $new_level; |
40
|
|
|
|
|
|
|
|
41
|
27
|
|
|
|
|
40
|
return; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub level { |
45
|
2
|
|
|
2
|
0
|
12
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
50
|
|
|
10
|
return $self->{level} || 'error'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
0
|
0
|
sub log { return shift->_log( shift, @_) } |
51
|
3
|
|
|
3
|
0
|
825
|
sub info { return shift->_log( 'info', @_ ) } |
52
|
13
|
|
|
13
|
0
|
2643
|
sub error { return shift->_log( 'error', @_ ) } |
53
|
13
|
|
|
13
|
0
|
8149
|
sub warn { return shift->_log( 'warn', @_ ) } |
54
|
12
|
|
|
12
|
0
|
6730
|
sub debug { return shift->_log( 'debug', @_ ) } |
55
|
1
|
|
|
1
|
0
|
290
|
sub trace { return shift->_log( 'trace', @_ ) } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _log { |
58
|
42
|
|
|
42
|
|
53
|
my $self = shift; |
59
|
42
|
|
|
|
|
44
|
my $level = shift; |
60
|
42
|
|
|
|
|
43
|
my $message = shift; |
61
|
|
|
|
|
|
|
|
62
|
42
|
100
|
|
|
|
103
|
return if $LEVELS->{$level} > $LEVELS->{ $self->{'level'} }; |
63
|
|
|
|
|
|
|
|
64
|
39
|
|
|
|
|
1235
|
my $time = Time::Moment->now->strftime('%Y-%m-%d %T%3f'); |
65
|
|
|
|
|
|
|
|
66
|
39
|
|
|
|
|
190
|
my $text = sprintf("%s [%s] %s\n", $time, $level, $message); |
67
|
39
|
100
|
|
|
|
102
|
$text = sprintf($text, @_) if (@_); |
68
|
|
|
|
|
|
|
|
69
|
39
|
|
|
|
|
107
|
$self->_print($text); |
70
|
|
|
|
|
|
|
|
71
|
39
|
|
|
|
|
156
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
|
|
sub _print { croak 'Not implemented!' } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |