blib/lib/Log/Abstraction/Backend/LogDispatch.pm

filter: Statementstmt 100% 25 / 25 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 97.2% 35 / 36 CC 3 SCAR 5.6
CC
3
Cov
97%
emit
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« blib/lib/Log/Abstraction/Backend/Code.pm ↑ Summary blib/lib/Log/Abstraction/Backend.pm »
1 package Log::Abstraction::Backend::LogDispatch;
2  
3 # The log_dispatch backend: send messages on to Log::Dispatch
4 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 42 ▶use parent 'Log::Abstraction::Backend';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 42 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 42 ▶use Readonly ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 42 our $VERSION = '0.40';
13  
14 # The Log::Dispatch level name for each internal level name
15 42 Readonly::Hash my %LEVEL => (
16 trace => 'debug', # Log::Dispatch has nothing below debug
17 debug => 'debug',
18 info => 'info',
19 notice => 'notice',
20 warn => 'warning',
21 error => 'error',
22 critical => 'critical',
23 alert => 'alert',
24 emergency => 'emergency',
25 );
26  
27 =head1 NAME
28  
29 Log::Abstraction::Backend::LogDispatch - send messages on to Log::Dispatch
30  
31 =head1 VERSION
32  
33 0.40
34  
35 =head1 DESCRIPTION
36  
37 Built for the C<log_dispatch> key of a C<logger> hash, or a
38 L<Log::Dispatch> object as the C<logger>. Calls its C<log()> method with
39 the level (C<warn> becomes C<warning>, and C<trace>, which Log::Dispatch
40 doesn't have, C<debug>) and the message with the structured fields as
41 C<key=value> text, or with a C<format> the formatted line. If
42 Log::Dispatch dies, it carps.
43  
44 Nothing is sent while a message is already being forwarded (see
45 C<$Log::Abstraction::Backend::FORWARDING>).
46  
47 For use by L<Log::Abstraction> only; see L<Log::Abstraction::Backend>.
48  
49 =head1 METHODS
50  
51 =head2 emit
52  
53 $backend->emit($logger, $event);
54  
55 =cut
56  
57 15 ▶sub emit {
Subroutine emit: called CC=3 SCAR=11.0
Pod documented
58 15 my ($self, $logger, $event) = @_;
59  
60 15 ▶ return if($Log::Abstraction::Backend::FORWARDING);
Branch: 1 branch
BranchTrueFalseTotal
if $Log::Abstraction::Backend::FORWARDING 0 15 15
61 15 local $Log::Abstraction::Backend::FORWARDING = 1;
62  
63 15 my $ok = eval {
64 $self->{'log_dispatch'}->log(
65 level => $LEVEL{$event->{'level'}},
66 15 message => $self->text($event, $event->{'text'}),
67 );
68 14 1;
69 };
70 15 ▶ Carp::carp(ref($logger), ": Log::Dispatch failed: $@") if(!$ok);
Branch: 1 branch
BranchTrueFalseTotal
if not $ok 1 14 15
71 }
72  
73 =head1 AUTHOR
74  
75 Nigel Horne C<njh@nigelhorne.com>
76  
77 =head1 SEE ALSO
78  
79 L<Log::Abstraction>, L<Log::Abstraction::Backend>
80  
81 =head1 COPYRIGHT AND LICENSE
82  
83 Copyright (C) 2025-2026 Nigel Horne
84  
85 Usage is subject to the GPL2 licence terms.
86 If you use it,
87 please let me know.
88  
89 =cut
90  
91 42 1;
« blib/lib/Log/Abstraction/Backend/Code.pm ↑ Summary blib/lib/Log/Abstraction/Backend.pm »