line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::ger::Output::Callback; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-03-07'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Log-ger-Output-Callback'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.006'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
9609
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
194
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_hooks { |
13
|
1
|
|
|
1
|
0
|
12
|
my %plugin_conf = @_; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
2
|
my $hooks = {}; |
16
|
|
|
|
|
|
|
|
17
|
1
|
50
|
|
|
|
4
|
if ($plugin_conf{logging_cb}) { |
18
|
|
|
|
|
|
|
$hooks->{create_outputter} = [ |
19
|
|
|
|
|
|
|
__PACKAGE__, # key |
20
|
|
|
|
|
|
|
# we want to handle all levels, thus we need to be higher priority |
21
|
|
|
|
|
|
|
# than default Log::ger hooks (10) which will install null loggers |
22
|
|
|
|
|
|
|
# for less severe levels. |
23
|
|
|
|
|
|
|
9, # priority |
24
|
|
|
|
|
|
|
sub { # hook |
25
|
6
|
|
|
6
|
|
612
|
my %hook_args = @_; |
26
|
|
|
|
|
|
|
my $outputter = sub { |
27
|
3
|
|
|
|
|
1339
|
my ($per_target_conf, $msg, $per_msg_conf) = @_; |
28
|
3
|
|
33
|
|
|
11
|
my $level = $per_msg_conf->{level} // $hook_args{level}; |
29
|
3
|
|
|
|
|
7
|
$plugin_conf{logging_cb}->($per_target_conf, $level, $msg, $per_msg_conf); |
30
|
6
|
|
|
|
|
19
|
}; |
31
|
6
|
|
|
|
|
15
|
[$outputter]; |
32
|
|
|
|
|
|
|
}, |
33
|
1
|
|
|
|
|
5
|
]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
|
|
|
3
|
if ($plugin_conf{detection_cb}) { |
37
|
|
|
|
|
|
|
$hooks->{create_level_checker} = [ |
38
|
|
|
|
|
|
|
__PACKAGE__, # key |
39
|
|
|
|
|
|
|
9, # priority |
40
|
|
|
|
|
|
|
sub { # hook |
41
|
0
|
|
|
0
|
|
0
|
my %hook_args = @_; |
42
|
|
|
|
|
|
|
my $level_checker = sub { |
43
|
0
|
|
|
|
|
0
|
$plugin_conf{detection_cb}->($hook_args{level}); |
44
|
0
|
|
|
|
|
0
|
}; |
45
|
0
|
|
|
|
|
0
|
[$level_checker]; |
46
|
|
|
|
|
|
|
}, |
47
|
0
|
|
|
|
|
0
|
]; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
3
|
return $hooks; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
# ABSTRACT: Send logs to a subroutine |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |