line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::Multiplexor; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15991
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
26
|
|
7
|
1
|
|
|
1
|
|
497
|
use utf8; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
483
|
use open qw(:std :utf8); |
|
1
|
|
|
|
|
1014
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
142
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
99
|
|
10
|
1
|
|
|
1
|
|
215
|
use Log::Any::Adapter; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#Default adapter |
12
|
|
|
|
|
|
|
Log::Any::Adapter->set('Stdout'); |
13
|
|
|
|
|
|
|
use Data::Printer; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %LOG_LEVELS = ( |
18
|
|
|
|
|
|
|
'0' => 'EMERGENCY', |
19
|
|
|
|
|
|
|
'1' => 'ALERT', |
20
|
|
|
|
|
|
|
'2' => 'CRITICAL', |
21
|
|
|
|
|
|
|
'3' => 'ERROR', |
22
|
|
|
|
|
|
|
'4' => 'WARNING', |
23
|
|
|
|
|
|
|
'5' => 'NOTICE', |
24
|
|
|
|
|
|
|
'6' => 'INFO', |
25
|
|
|
|
|
|
|
'7' => 'DEBUG', |
26
|
|
|
|
|
|
|
'8' => 'TRACE', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
|
|
|
|
|
|
my $class = shift; |
31
|
|
|
|
|
|
|
my $log = shift; |
32
|
|
|
|
|
|
|
my %opt = @_; |
33
|
|
|
|
|
|
|
my $self = {}; |
34
|
|
|
|
|
|
|
$self->{log} = $log; |
35
|
|
|
|
|
|
|
bless $self, $class; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
for my $key (keys %opt) { |
39
|
|
|
|
|
|
|
my $adapter = shift @{$opt{$key}}; |
40
|
|
|
|
|
|
|
my @param = @{$opt{$key}}; |
41
|
|
|
|
|
|
|
$self->set_logger($key, $adapter, @param); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$log->{filter} = sub { |
46
|
|
|
|
|
|
|
no strict 'refs'; |
47
|
|
|
|
|
|
|
my $log_level_name = $LOG_LEVELS{$_[1]} || 'trace'; |
48
|
|
|
|
|
|
|
$log_level_name = lc($log_level_name); |
49
|
|
|
|
|
|
|
$self->{adapters}->{$log_level_name}->$log_level_name($_[2]); |
50
|
|
|
|
|
|
|
return ''; |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return $self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub set_logger { |
58
|
|
|
|
|
|
|
no strict 'refs'; |
59
|
|
|
|
|
|
|
my ($self, $log_level, $package, @param) = @_; |
60
|
|
|
|
|
|
|
my $log = $self->{log}; |
61
|
|
|
|
|
|
|
$self->{adapters}->{$log_level} = $log->clone(); |
62
|
|
|
|
|
|
|
eval "require $package"; |
63
|
|
|
|
|
|
|
if ($@) { |
64
|
|
|
|
|
|
|
croak $@; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
$self->{adapters}->{$log_level} = $package->new(@param); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |