line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Commando::Logger; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
25864
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
170
|
|
4
|
5
|
|
|
5
|
|
30
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
127
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
26
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
339
|
|
7
|
5
|
|
|
5
|
|
776
|
use Moo; |
|
5
|
|
|
|
|
15666
|
|
|
5
|
|
|
|
|
25
|
|
8
|
5
|
|
|
5
|
|
3028
|
use Scalar::Util qw(openhandle); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
9306
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'device' => ( is => 'ro' ); |
11
|
|
|
|
|
|
|
has 'formatter' => ( is => 'rw' ); |
12
|
|
|
|
|
|
|
has 'level' => ( is => 'rw' ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub BUILDARGS { |
15
|
13
|
|
|
13
|
0
|
14121
|
my ($class, $device) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
return { |
18
|
13
|
|
|
|
|
280
|
device => $device, |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub BUILD { |
23
|
13
|
|
|
13
|
0
|
200
|
my ($self) = @_; |
24
|
|
|
|
|
|
|
|
25
|
13
|
|
|
|
|
25
|
eval { |
26
|
13
|
|
|
|
|
71
|
$self->{_fh} = openhandle($self->device); |
27
|
13
|
100
|
|
|
|
113
|
open($self->{_fh}, '>>', $self->device) if !defined $self->{_fh}; |
28
|
|
|
|
|
|
|
}; |
29
|
13
|
100
|
|
|
|
36
|
if ($@) { |
30
|
1
|
|
|
|
|
172
|
croak 'Can\'t open log device'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
12
|
|
|
|
|
250
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my %levels = ( |
37
|
|
|
|
|
|
|
'debug' => 1, |
38
|
|
|
|
|
|
|
'info' => 2, |
39
|
|
|
|
|
|
|
'warn' => 3, |
40
|
|
|
|
|
|
|
'error' => 4, |
41
|
|
|
|
|
|
|
'fatal' => 5, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _store { |
45
|
11
|
|
|
11
|
|
19
|
my ($self, $level, $message) = @_; |
46
|
|
|
|
|
|
|
|
47
|
11
|
50
|
|
|
|
66
|
if ($levels{lc $level} >= $levels{lc $self->{level}}) { |
48
|
0
|
0
|
|
|
|
0
|
print { $self->{_fh} } |
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
ref($self->formatter) eq 'CODE' ? |
50
|
|
|
|
|
|
|
$self->formatter->($level, $message) : $message; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub debug { |
55
|
11
|
|
|
11
|
0
|
51
|
my ($self, $message) = @_; |
56
|
|
|
|
|
|
|
|
57
|
11
|
|
|
|
|
35
|
$self->_store('debug', $message); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub info { |
61
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->_store('info', $message); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub warn { |
67
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->_store('warn', $message); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub error { |
73
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$self->_store('error', $message); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub fatal { |
79
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->_store('fatal', $message); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |