blib/lib/Log/ger/Output/LogDispatchOutput.pm

filter: Statementstmt 100% 31 / 31 Branchbran 66.6% 4 / 6 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 76.2% 45 / 59 CC 7 SCAR 14.1
CC
7
Cov
84%
__ANON__
7.3
get_hooks
2.1
__ANON__
1.0
CRAP 4.1
↑ Summary
1 package Log::ger::Output::LogDispatchOutput;
2  
3 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 2 our $DATE = '2020-03-11'; # DATE
5 2 our $DIST = 'Log-ger-Output-LogDispatchOutput'; # DIST
6 2 our $VERSION = '0.006'; # VERSION
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Log::ger::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶sub meta { +{
Subroutine meta: called CC=1 SCAR=0.0
Pod undocumented
14 1 v => 2,
15 } }
16  
17 1 ▶sub get_hooks {
Subroutine get_hooks: called CC=2 SCAR=7.2
Pod undocumented
18 1 my %plugin_conf = @_;
19  
20 1 ▶ $plugin_conf{output} or die "Please specify output (e.g. ".
Branch: 1 branch
BranchTrueFalseTotal
$plugin_conf{"output"} or die "Please specify output (e.g. ArrayWithLimits for Log::Dispatch::ArrayWithLimits)" 1 0 1
21 "ArrayWithLimits for Log::Dispatch::ArrayWithLimits)";
22  
23 1 require Log::Dispatch;
24 1 my $mod = "Log::Dispatch::$plugin_conf{output}";
25 1 (my $mod_pm = "$mod.pm") =~ s!::!/!g;
26 1 require $mod_pm;
27  
28 return {
29 create_outputter => [
30 __PACKAGE__, # key
31 # we want to handle all levels, thus we need to be higher priority
32 # than default Log::ger hooks (10) which will install null loggers
33 # for less severe levels.
34 9, # priority
35 12 ▶ sub { # hook
Subroutine __ANON__: called CC=1 SCAR=0.2
36 12 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
37  
38 3 ▶ my $outputter = sub {
Subroutine __ANON__: called CC=6 SCAR=19.9
39 3 my ($per_target_conf, $msg, $per_msg_conf) = @_;
40 3 ▶ my $level = $per_msg_conf->{level} // $hook_args{level};
Condition33%1/3
$per_msg_conf->{"level"} // $hook_args{"level"}
l!l&&r!l&&!r
030
MC/DC0%0/2
$per_msg_conf->{"level"} // $hook_args{"level"}
$per_msg_conf->{"level"} $hook_args{"level"}
Truth table33%1/3
A // B
A= $per_msg_conf->{"level"}B= $hook_args{"level"}
ABresult
1X1
011
000
41  
42 3 ▶ return if $level > $Log::ger::Current_Level;
Branch: 1 branch
BranchTrueFalseTotal
if $level > $Log::ger::Current_Level 1 2 3
43  
44 # we can use per-target conf to store per-target stuffs
45 $hook_args{per_target_conf}{_ld} ||= Log::Dispatch->new(
46 outputs => [
47 $plugin_conf{_output} ? $plugin_conf{_output} :
48 [
49 $plugin_conf{output},
50 min_level => 'warning',
51 2 ▶ %{ $plugin_conf{args} || {} },
Branch: 1 branch
BranchTrueFalseTotal
$plugin_conf{'_output'} ? : 0 2 2
Condition40%2/5
$hook_args{"per_target_conf"}{"_ld"} ||= "Log::Dispatch"->new("outputs", [$plugin_conf{"_output"} ? $plugin_conf{"_output"} : [$plugin_conf{"output"}, "min_level", "warning", %{$plugin_conf{"args"} or {};}]])
l!l&&r!l&&!r
020
$plugin_conf{'args'} || {}
l!l
20
MC/DC0%0/2
$hook_args{"per_target_conf"}{"_ld"} ||= "Log::Dispatch"->new("outputs", [$plugin_conf{"_output"} ? $plugin_conf{"_output"} : [$plugin_conf{"output"}, "min_level", "warning", %{$plugin_conf{"args"} or {};}]])
$hook_args{"per_target_conf"}{"_ld"} "Log::Dispatch"->new("outputs", [$plugin_conf{"_output"} ? $plugin_conf{"_output"} : [$plugin_conf{"output"}, "min_level", "warning", %{$plugin_conf{"args"} or {};}]])
MC/DC0%0/1
$plugin_conf{'args'} || {}
$plugin_conf{'args'}
Truth table33%1/3
A ||= B
A= $hook_args{"per_target_conf"}{"_ld"}B= "Log::Dispatch"->new("outputs", [$plugin_conf{"_output"} ? $plugin_conf{"_output"} : [$plugin_conf{"output"}, "min_level", "warning", %{$plugin_conf{"args"} or {};}]])
ABresult
1X1
011
000
Truth table50%1/2
A
A= $plugin_conf{'args'}
Aresult
11
00
52 ],
53 ],
54 );
55 2 $hook_args{per_target_conf}{_ld}->warning($msg);
56 12 };
57 12 [$outputter];
58 1 }],
59 };
60 }
61  
62 2 1;
63 # ABSTRACT: Send logs to a Log::Dispatch output
64  
65 __END__
↑ Summary