| 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-11'; # DATE |
|
5
|
|
|
|
|
|
|
our $DIST = 'Log-ger-Output-Callback'; # DIST |
|
6
|
|
|
|
|
|
|
our $VERSION = '0.009'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
11132
|
use 5.010001; |
|
|
1
|
|
|
|
|
4
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
361
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub meta { +{ |
|
13
|
1
|
|
|
1
|
0
|
16
|
v => 2, |
|
14
|
|
|
|
|
|
|
} } |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get_hooks { |
|
17
|
1
|
|
|
1
|
0
|
14
|
my %plugin_conf = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
3
|
my $hooks = {}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
50
|
|
|
|
4
|
if ($plugin_conf{logging_cb}) { |
|
22
|
|
|
|
|
|
|
$hooks->{create_outputter} = [ |
|
23
|
|
|
|
|
|
|
__PACKAGE__, # key |
|
24
|
|
|
|
|
|
|
# we want to handle all levels, thus we need to be higher priority |
|
25
|
|
|
|
|
|
|
# than default Log::ger hooks (10) which will install null loggers |
|
26
|
|
|
|
|
|
|
# for less severe levels. |
|
27
|
|
|
|
|
|
|
9, # priority |
|
28
|
|
|
|
|
|
|
sub { # hook |
|
29
|
6
|
|
|
6
|
|
655
|
my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook" |
|
30
|
|
|
|
|
|
|
my $outputter = sub { |
|
31
|
3
|
|
|
|
|
1588
|
my ($per_target_conf, $msg, $per_msg_conf) = @_; |
|
32
|
3
|
50
|
|
|
|
6
|
my $level = $per_msg_conf ? $per_msg_conf->{level} : undef; $level = $hook_args{level} if !defined $level; |
|
|
3
|
50
|
|
|
|
8
|
|
|
33
|
3
|
|
|
|
|
7
|
$plugin_conf{logging_cb}->($per_target_conf, $level, $msg, $per_msg_conf); |
|
34
|
6
|
|
|
|
|
18
|
}; |
|
35
|
6
|
|
|
|
|
13
|
[$outputter]; |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
1
|
|
|
|
|
5
|
]; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
50
|
|
|
|
3
|
if ($plugin_conf{detection_cb}) { |
|
41
|
|
|
|
|
|
|
$hooks->{create_level_checker} = [ |
|
42
|
|
|
|
|
|
|
__PACKAGE__, # key |
|
43
|
|
|
|
|
|
|
9, # priority |
|
44
|
|
|
|
|
|
|
sub { # hook |
|
45
|
0
|
|
|
0
|
|
0
|
my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook" |
|
46
|
|
|
|
|
|
|
my $level_checker = sub { |
|
47
|
0
|
|
|
|
|
0
|
$plugin_conf{detection_cb}->($hook_args{level}); |
|
48
|
0
|
|
|
|
|
0
|
}; |
|
49
|
0
|
|
|
|
|
0
|
[$level_checker]; |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
0
|
|
|
|
|
0
|
]; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
4
|
return $hooks; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
|
58
|
|
|
|
|
|
|
# ABSTRACT: Send logs to a subroutine |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |