1Log::Any::Adapter::CaptUusreer(3C)ontributed Perl DocumeLnotga:t:iAonny::Adapter::Capture(3)
2
3
4

NAME

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

VERSION

10       version 1.708
11

SYNOPSIS

13         # temporarily redirect arrays of [ $level, $category, $message ] into an array
14         Log::Any::Adapter->set( { lexically => \my $scope }, Capture => to => \my @array );
15
16         # temporarily redirect just the text of log messages into an array
17         Log::Any::Adapter->set( { lexically => \my $scope }, Capture => text => \my @array );
18
19         # temporarily redirect the full argument list and context of each call, but only for
20         # log levels 'info' and above.
21         Log::Any::Adapter->set(
22           { lexically => \my $scope },
23           Capture =>
24               format => 'structured',
25               to => \my @array,
26               log_level => 'info'
27         );
28

DESCRIPTION

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

ATTRIBUTES

37   to
38       Specify a coderef or arrayref where the messages will be delivered.
39       The content pushed onto the array or passed to the coderef depends on
40       "format".
41
42   format
43       'messages'
44             sub ( $level, $category, $message_text ) { ... }
45             push @to, [ $level, $category, $message_text ];
46
47           This is the default format.  It passes/pushes 3 arguments: the name
48           of the log level, the logging category, and the message text as a
49           plain string.
50
51       'text'
52             sub ( $message_text ) { ... }
53             push @to, $message_text;
54
55           This format is the simplest, and only passes/pushes the text of the
56           message.
57
58       'structured'
59             sub ( $level, $category, @message_parts, \%context? ) { ... }
60             push @to, [ $level, $category, @message_parts, \%context? ];
61
62           This passes/pushes the full information available about the call to
63           the logging method.  The @message_parts are the actual arguments
64           passed to the logging method, and if the final argument is a
65           hashref, it is the combined "context" from the logging proxy and
66           any overrides passed to the logging method.
67
68   log_level
69       Like other logging adapters, this optional argument can filter out any
70       log messages above the specified threshhold.  The default is to pass
71       through all messages regardless of level.
72

ATTRIBUTE ALIASES

74       These are not actual attributes, just shortcuts for others:
75
76   text
77         text => $dest
78
79       is shorthand for
80
81         format => 'text', to => $dest
82
83   structured
84         structured => $dest
85
86       is shorthand for
87
88         format => 'structured', to => $dest
89

AUTHORS

91       ·   Jonathan Swartz <swartz@pobox.com>
92
93       ·   David Golden <dagolden@cpan.org>
94
95       ·   Doug Bell <preaction@cpan.org>
96
97       ·   Daniel Pittman <daniel@rimspace.net>
98
99       ·   Stephen Thirlwall <sdt@cpan.org>
100
102       This software is copyright (c) 2017 by Jonathan Swartz, David Golden,
103       and Doug Bell.
104
105       This is free software; you can redistribute it and/or modify it under
106       the same terms as the Perl 5 programming language system itself.
107
108
109
110perl v5.32.0                      2020-07-28     Log::Any::Adapter::Capture(3)
Impressum