« blib/lib/Log/Abstraction/Backend/Syslog.pm
↑ Summary
blib/lib/Log/Abstraction/Backend/LogDispatch.pm »
| 1 | package Log::Abstraction::Backend::Code; | ||||||||||
| 2 | |||||||||||
| 3 | # The code-reference backend: call it with a hash of the message | ||||||||||
| 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 | our $VERSION = '0.40'; | |||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | Log::Abstraction::Backend::Code - call a code reference with each message | ||||||||||
| 14 | |||||||||||
| 15 | =head1 VERSION | ||||||||||
| 16 | |||||||||||
| 17 | 0.40 | ||||||||||
| 18 | |||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||
| 20 | |||||||||||
| 21 | Built for C<logger =E<gt> \&code>. The code is called with | ||||||||||
| 22 | C<{ class, file, line, level, message, ctx, fields }>, where C<message> is an | ||||||||||
| 23 | array reference of the message's parts, and C<ctx> and C<fields> are only | ||||||||||
| 24 | present when set. | ||||||||||
| 25 | |||||||||||
| 26 | For use by L<Log::Abstraction> only; see L<Log::Abstraction::Backend>. | ||||||||||
| 27 | |||||||||||
| 28 | =head1 METHODS | ||||||||||
| 29 | |||||||||||
| 30 | =head2 emit | ||||||||||
| 31 | |||||||||||
| 32 | $backend->emit($logger, $event); | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | 43 | ▶ | sub emit { | ||||||||
|
Subroutine
emit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 37 | 43 | my ($self, $logger, $event) = @_; | |||||||||
| 38 | |||||||||||
| 39 | my $args = { | ||||||||||
| 40 | class => $event->{'class'}, | ||||||||||
| 41 | file => $event->{'file'}, | ||||||||||
| 42 | line => $event->{'line'}, | ||||||||||
| 43 | level => $event->{'level'}, | ||||||||||
| 44 | 43 | message => $event->{'parts'}, | |||||||||
| 45 | }; | ||||||||||
| 46 | 43 | ▶ | $args->{'ctx'} = $event->{'ctx'} if($event->{'ctx'}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 43 | ▶ | $args->{'fields'} = $event->{'fields'} if($event->{'fields'}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 43 | $self->{'code'}->($args); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | =head1 AUTHOR | ||||||||||
| 52 | |||||||||||
| 53 | Nigel Horne C<njh@nigelhorne.com> | ||||||||||
| 54 | |||||||||||
| 55 | =head1 SEE ALSO | ||||||||||
| 56 | |||||||||||
| 57 | L<Log::Abstraction>, L<Log::Abstraction::Backend> | ||||||||||
| 58 | |||||||||||
| 59 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 60 | |||||||||||
| 61 | Copyright (C) 2025-2026 Nigel Horne | ||||||||||
| 62 | |||||||||||
| 63 | Usage is subject to the GPL2 licence terms. | ||||||||||
| 64 | If you use it, | ||||||||||
| 65 | please let me know. | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 42 | 1; | |||||||||