Log::An...Capture(3)
β¨ Log::Any::Adapter::Capture π
okay bestie, so this is Log::Any::Adapter::Capture, a Perl module from the User Contributed Perl Documentation, and it's literally the adapter that catches your log messages and drops them into an arrayref instead of letting them wander off into a log file. it's giving "log jail but make it cute" π
version 1.718 β yeah she's on 1.718, noted, slay.
πΈ SYNOPSIS πΈ
here's the vibe, bestie β three ways to do the thing:
# temporarily redirect arrays of [ $level, $category, $message ] into an array
Log::Any::Adapter->set( { lexically => \my $scope }, Capture => to => \my @array );
# temporarily redirect just the text of log messages into an array
Log::Any::Adapter->set( { lexically => \my $scope }, Capture => text => \my @array );
# temporarily redirect the full argument list and context of each call, but only for
# log levels 'info' and above.
Log::Any::Adapter->set(
{ lexically => \my $scope },
Capture =>
format => 'structured',
to => \my @array,
log_level => 'info'
);
π«Ά notice the lexically => \my $scope thing? that's the whole "temporarily" part. it only sticks around while that scope lives. iconic behaviour honestly.
π¦ DESCRIPTION π¦
so this logging adapter is your little shortcut for grabbing log messages into a callback or an arrayref of your choosing, without you having to go write your own whole adapter from scratch. like, why would you. we already did it. π
it's made for those times when you want to temporarily capture log messages β for example, showing them to a user of your app instead of having them get written into some log file somewhere. main character energy for your error messages, fr fr. β¨
π ATTRIBUTES π
π to
so you say a coderef or an arrayref here, and that's where the messages get delivered. the actual content that gets pushed onto the array or handed to the coderef? that depends entirely on format. iykyk.
π format
three flavours, bestie, pick your fighter:
β 'messages'
sub ( $level, $category, $message_text ) { ... }
push @to, [ $level, $category, $message_text ];
this one is the default, no cap. it passes/pushes 3 arguments: the name of the log level, the logging category, and the message text as a plain string. three lil guys. adorable.
β 'text'
sub ( $message_text ) { ... }
push @to, $message_text;
the simplest format, periodt. it only passes/pushes the text of the message. that's it. that's the whole thing. minimalism ate.
β 'structured'
sub ( $level, $category, @message_parts, \%context? ) { ... }
push @to, [ $level, $category, @message_parts, \%context? ];
okay this one is the full send. it passes/pushes literally all the information available about the call to the logging method. the @message_parts are the actual arguments that got passed to the logging method β like, the real ones β and if the final argument is a hashref, then that's the combined "context" from the logging proxy plus any overrides that were passed to the logging method. everything. all of it. we're not gatekeeping here. π
π log_level
just like other logging adapters, this optional argument can filter out any log messages above the specified threshhold. the default? pass everything through, regardless of level. no filter, no judgement, we accept all messages in this house. π«Ά
β¨ ATTRIBUTE ALIASES β¨
plot twist bestie β these aren't actual attributes, they're just shortcuts for the others. cute little nicknames. π
πΈ text
text => $dest
is shorthand for
format => 'text', to => $dest
πΈ structured
structured => $dest
is shorthand for
format => 'structured', to => $dest
π AUTHORS π
- Jonathan Swartz <swartz@pobox.com>
- David Golden <dagolden@cpan.org>
- Doug Bell <preaction@cpan.org>
- Daniel Pittman <daniel@rimspace.net>
- Stephen Thirlwall <sdt@cpan.org>
five whole legends, we love a collab π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in go wild bestie, just keep the same terms. β¨
and that's the whole page, bestie!! this one shipped with perl v5.42.0, dated 2025-07-28 β so yeah, she's fresh, she's documented, and she's ready to capture your logs. mwah. π ππΈ
π¦ where this page comes from
- fedora 43: perl-Log-Any 1.718-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms