| 1 |
package Dancer2::Logger::Capture::Trap; |
| 2 |
# ABSTRACT: a place to store captured Dancer2 logs |
| 3 |
$Dancer2::Logger::Capture::Trap::VERSION = '2.2.2'; |
| 4 |
use Moo; |
| 5 |
use Dancer2::Core::Types; |
| 6 |
|
| 7 |
has storage => ( |
| 8 |
is => 'rw', |
| 9 |
isa => ArrayRef, |
| 10 |
default => sub { [] }, |
| 11 |
); |
| 12 |
|
| 13 |
sub store { |
| 14 |
my ( $self, $level, $message, $fmt_string ) = @_; |
| 15 |
push @{ $self->storage }, { |
| 16 |
level => $level, |
| 17 |
message => $message, |
| 18 |
formatted => $fmt_string, |
| 19 |
}; |
| 20 |
} |
| 21 |
|
| 22 |
sub read { |
| 23 |
my $self = shift; |
| 24 |
|
| 25 |
my $logs = $self->storage; |
| 26 |
$self->storage( [] ); |
| 27 |
return $logs; |
| 28 |
} |
| 29 |
|
| 30 |
1; |
| 31 |
|
| 32 |
__END__ |
| 33 |
|
| 34 |
=pod |
| 35 |
|
| 36 |
=encoding UTF-8 |
| 37 |
|
| 38 |
=head1 NAME |
| 39 |
|
| 40 |
Dancer2::Logger::Capture::Trap - a place to store captured Dancer2 logs |
| 41 |
|
| 42 |
=head1 VERSION |
| 43 |
|
| 44 |
version 2.2.2 |
| 45 |
|
| 46 |
=head1 SYNOPSIS |
| 47 |
|
| 48 |
my $trap = Dancer2::Logger::Capture::Trap->new; |
| 49 |
$trap->store( $level, $message ); |
| 50 |
my $logs = $trap->read; |
| 51 |
|
| 52 |
=head1 DESCRIPTION |
| 53 |
|
| 54 |
This is a place to store and retrieve capture Dancer2 logs used by |
| 55 |
L<Dancer2::Logger::Capture>. |
| 56 |
|
| 57 |
=head2 Methods |
| 58 |
|
| 59 |
=head3 new |
| 60 |
|
| 61 |
=head3 store |
| 62 |
|
| 63 |
$trap->store($level, $message); |
| 64 |
|
| 65 |
Stores a log $message and its $level. |
| 66 |
|
| 67 |
=head3 read |
| 68 |
|
| 69 |
my $logs = $trap->read; |
| 70 |
|
| 71 |
Returns the logs stored as an array ref and clears the storage. |
| 72 |
|
| 73 |
For example... |
| 74 |
|
| 75 |
[{ level => "warning", message => "Danger! Warning! Dancer2!" }, |
| 76 |
{ level => "error", message => "You fail forever" } |
| 77 |
]; |
| 78 |
|
| 79 |
=head1 SEE ALSO |
| 80 |
|
| 81 |
L<Dancer2::Logger::Capture> |
| 82 |
|
| 83 |
=head1 AUTHOR |
| 84 |
|
| 85 |
Dancer Core Developers |
| 86 |
|
| 87 |
=head1 COPYRIGHT AND LICENSE |
| 88 |
|
| 89 |
This software is copyright (c) 2026 by Alexis Sukrieh. |
| 90 |
|
| 91 |
This is free software; you can redistribute it and/or modify it under |
| 92 |
the same terms as the Perl 5 programming language system itself. |
| 93 |
|
| 94 |
=cut |