GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Log::Any::Adapter::Capture(3) User Contributed Perl Documentation Log::Any::Adapter::Capture(3)

Log::Any::Adapter::Capture - Adapter for capturing log messages into an arrayref

version 1.710

  # 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'
  );

This logging adapter provides a convenient way to capture log messages into a callback or arrayref of your choice without needing to write your own adapter. It is intended for cases where you want to temporarily capture log messages, such as showing them to a user of your application rather than having them written to a log file.

Specify a coderef or arrayref where the messages will be delivered. The content pushed onto the array or passed to the coderef depends on "format".

'messages'
  sub ( $level, $category, $message_text ) { ... }
  push @to, [ $level, $category, $message_text ];
    

This is the default format. It passes/pushes 3 arguments: the name of the log level, the logging category, and the message text as a plain string.

'text'
  sub ( $message_text ) { ... }
  push @to, $message_text;
    

This format is the simplest, and only passes/pushes the text of the message.

'structured'
  sub ( $level, $category, @message_parts, \%context? ) { ... }
  push @to, [ $level, $category, @message_parts, \%context? ];
    

This passes/pushes the full information available about the call to the logging method. The @message_parts are the actual arguments passed to the logging method, and if the final argument is a hashref, it is the combined "context" from the logging proxy and any overrides passed to the logging method.

Like other logging adapters, this optional argument can filter out any log messages above the specified threshhold. The default is to pass through all messages regardless of level.

These are not actual attributes, just shortcuts for others:

  text => $dest

is shorthand for

  format => 'text', to => $dest

  structured => $dest

is shorthand for

  format => 'structured', to => $dest

  • 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>

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.

2021-08-02 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.