File Coverage

File:blib/lib/Log/Abstraction/Backend/Array.pm
Coverage:100.0%

linestmtbrancondsubtimecode
1package Log::Abstraction::Backend::Array;
2
3# The array backend: push the history entry onto an array
4
37
37
37
101
21
168
use strict;
5
37
37
37
32
21
325
use warnings;
6
7
37
37
37
32
21
70
use parent 'Log::Abstraction::Backend';
8
9our $VERSION = '0.40';
10
11 - 34
=head1 NAME

Log::Abstraction::Backend::Array - push messages onto an array

=head1 VERSION

0.40

=head1 DESCRIPTION

Built for C<logger =E<gt> \@array>, a top-level C<array>, or the C<array>
key of a C<logger> hash.  Pushes C<{ level, message }> hash references, with
C<fields> when the message has structured fields.  With a C<format>, the
C<message> is the formatted line.

For use by L<Log::Abstraction> only; see L<Log::Abstraction::Backend>.

=head1 METHODS

=head2 emit

  $backend->emit($logger, $event);

=cut
35
36sub emit {
37
10626
4366
        my ($self, $logger, $event) = @_;
38
39
10626
4413
        push @{$self->{'array'}}, {
40
10626
23084
                @{$event->{'entry'}},
41
10626
3891
                (defined($self->{'format'}) ? (message => $event->{'render'}->($self->{'format'})) : ()),
42        };
43}
44
45 - 61
=head1 AUTHOR

Nigel Horne C<njh@nigelhorne.com>

=head1 SEE ALSO

L<Log::Abstraction>, L<Log::Abstraction::Backend>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2025-2026 Nigel Horne

Usage is subject to the GPL2 licence terms.
If you use it,
please let me know.

=cut
62
631;