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 πŸ’œ


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