line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IRC::Indexer::Logger; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23127
|
use 5.10.1; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
50
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
77
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw/blessed/; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
134
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
80276
|
use Log::Handler; |
|
1
|
|
|
|
|
105338
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
0
|
163
|
my $self = {}; |
14
|
2
|
|
|
|
|
4
|
my $class = shift; |
15
|
2
|
|
|
|
|
5
|
bless $self, $class; |
16
|
|
|
|
|
|
|
## Set up a Log::Handler for specified LogFile |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
6
|
my %args = @_; |
19
|
2
|
|
|
|
|
15
|
$args{lc $_} = delete $args{$_} for keys %args; |
20
|
|
|
|
|
|
|
|
21
|
2
|
100
|
|
|
|
7
|
if ($args{devnull}) { |
22
|
|
|
|
|
|
|
## Sometimes it's useful to have a log object present, |
23
|
|
|
|
|
|
|
## but not necessarily logging anywhere: |
24
|
1
|
|
|
|
|
3
|
$self->{DevNull} = 1; |
25
|
|
|
|
|
|
|
} else { |
26
|
1
|
|
33
|
|
|
7
|
$self->{LogFile} = $args{logfile} |
27
|
|
|
|
|
|
|
|| croak "No LogFile specified in new()"; |
28
|
|
|
|
|
|
|
} |
29
|
2
|
|
50
|
|
|
14
|
$self->{LogLevel} = $args{loglevel} || 'info' ; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
8
|
$self->logger( $self->_create_logger ); |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
8
|
return $self |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _create_logger { |
37
|
2
|
|
|
2
|
|
2
|
my ($self) = @_; |
38
|
2
|
|
|
|
|
13
|
my $logger = Log::Handler->new(); |
39
|
2
|
100
|
|
|
|
146
|
$logger->add( |
40
|
|
|
|
|
|
|
file => { |
41
|
|
|
|
|
|
|
maxlevel => $self->{LogLevel}, |
42
|
|
|
|
|
|
|
timeformat => "%Y/%m/%d %H:%M:%S", |
43
|
|
|
|
|
|
|
message_layout => "[%T] %L %p %m", |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
filename => $self->{LogFile}, |
46
|
|
|
|
|
|
|
filelock => 1, |
47
|
|
|
|
|
|
|
fileopen => 1, |
48
|
|
|
|
|
|
|
reopen => 1, |
49
|
|
|
|
|
|
|
utf8 => 1, |
50
|
|
|
|
|
|
|
autoflush => 1, |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
) unless $self->{DevNull}; |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
4859
|
return $logger |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub logger { |
58
|
4
|
|
|
4
|
0
|
1109
|
my ($self, $logger) = @_; |
59
|
|
|
|
|
|
|
## Return/set our Log::Handler |
60
|
4
|
100
|
|
|
|
21
|
return $self->{LogObj} = $logger if blessed $logger; |
61
|
2
|
|
|
|
|
7
|
return $self->{LogObj} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub log_to { |
65
|
|
|
|
|
|
|
## Adjust the log destination |
66
|
0
|
|
|
0
|
0
|
|
my ($self, $path) = @_; |
67
|
0
|
0
|
|
|
|
|
return unless $path; |
68
|
0
|
|
|
|
|
|
$self->{LogFile} = $path; |
69
|
0
|
|
|
|
|
|
$self->logger->flush; |
70
|
0
|
|
|
|
|
|
$self->logger( $self->_create_logger ); |
71
|
0
|
|
|
|
|
|
return $self->logger |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
__END__ |