.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Log::Any::Adapter::Capture 3" .TH Log::Any::Adapter::Capture 3 2024-09-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Log::Any::Adapter::Capture \- Adapter for capturing log messages into an arrayref .SH VERSION .IX Header "VERSION" version 1.717 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& # temporarily redirect arrays of [ $level, $category, $message ] into an array \& Log::Any::Adapter\->set( { lexically => \emy $scope }, Capture => to => \emy @array ); \& \& # temporarily redirect just the text of log messages into an array \& Log::Any::Adapter\->set( { lexically => \emy $scope }, Capture => text => \emy @array ); \& \& # temporarily redirect the full argument list and context of each call, but only for \& # log levels \*(Aqinfo\*(Aq and above. \& Log::Any::Adapter\->set( \& { lexically => \emy $scope }, \& Capture => \& format => \*(Aqstructured\*(Aq, \& to => \emy @array, \& log_level => \*(Aqinfo\*(Aq \& ); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" 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. .SH ATTRIBUTES .IX Header "ATTRIBUTES" .SS to .IX Subsection "to" 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". .SS format .IX Subsection "format" .ie n .IP \*(Aqmessages\*(Aq 4 .el .IP \f(CW\*(Aqmessages\*(Aq\fR 4 .IX Item "messages" .Vb 2 \& sub ( $level, $category, $message_text ) { ... } \& push @to, [ $level, $category, $message_text ]; .Ve .Sp 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. .ie n .IP \*(Aqtext\*(Aq 4 .el .IP \f(CW\*(Aqtext\*(Aq\fR 4 .IX Item "text" .Vb 2 \& sub ( $message_text ) { ... } \& push @to, $message_text; .Ve .Sp This format is the simplest, and only passes/pushes the text of the message. .ie n .IP \*(Aqstructured\*(Aq 4 .el .IP \f(CW\*(Aqstructured\*(Aq\fR 4 .IX Item "structured" .Vb 2 \& sub ( $level, $category, @message_parts, \e%context? ) { ... } \& push @to, [ $level, $category, @message_parts, \e%context? ]; .Ve .Sp This passes/pushes the full information available about the call to the logging method. The \f(CW@message_parts\fR are the actual arguments passed to the logging method, and if the final argument is a hashref, it is the combined \f(CW\*(C`context\*(C'\fR from the logging proxy and any overrides passed to the logging method. .SS log_level .IX Subsection "log_level" 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. .SH "ATTRIBUTE ALIASES" .IX Header "ATTRIBUTE ALIASES" These are not actual attributes, just shortcuts for others: .SS text .IX Subsection "text" .Vb 1 \& text => $dest .Ve .PP is shorthand for .PP .Vb 1 \& format => \*(Aqtext\*(Aq, to => $dest .Ve .SS structured .IX Subsection "structured" .Vb 1 \& structured => $dest .Ve .PP is shorthand for .PP .Vb 1 \& format => \*(Aqstructured\*(Aq, to => $dest .Ve .SH AUTHORS .IX Header "AUTHORS" .IP \(bu 4 Jonathan Swartz .IP \(bu 4 David Golden .IP \(bu 4 Doug Bell .IP \(bu 4 Daniel Pittman .IP \(bu 4 Stephen Thirlwall .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.