.\" -*- 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 3" .TH Log::Any::Adapter 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 \- Tell Log::Any where to send its logs .SH VERSION .IX Header "VERSION" version 1.717 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 5 \& # Log to a file, or stdout, or stderr for all categories \& # \& use Log::Any::Adapter (\*(AqFile\*(Aq, \*(Aq/path/to/file.log\*(Aq); \& use Log::Any::Adapter (\*(AqStdout\*(Aq); \& use Log::Any::Adapter (\*(AqStderr\*(Aq); \& \& # Use Log::Log4perl for all categories \& # \& Log::Log4perl::init(\*(Aq/etc/log4perl.conf\*(Aq); \& Log::Any::Adapter\->set(\*(AqLog4perl\*(Aq); \& \& # Use Log::Dispatch for Foo::Baz \& # \& use Log::Dispatch; \& my $log = Log::Dispatch\->new(outputs => [[ ... ]]); \& Log::Any::Adapter\->set( { category => \*(AqFoo::Baz\*(Aq }, \& \*(AqDispatch\*(Aq, dispatcher => $log ); \& \& # Use Log::Dispatch::Config for Foo::Baz and its subcategories \& # \& use Log::Dispatch::Config; \& Log::Dispatch::Config\->configure(\*(Aq/path/to/log.conf\*(Aq); \& Log::Any::Adapter\->set( \& { category => qr/^Foo::Baz/ }, \& \*(AqDispatch\*(Aq, dispatcher => Log::Dispatch::Config\->instance() ); \& \& # Use your own adapter for all categories \& # \& Log::Any::Adapter\->set(\*(Aq+My::Log::Any::Adapter\*(Aq, ...); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Log::Any::Adapter connects log producers and log consumers. Its methods instantiate a logging adapter (a subclass of Log::Any::Adapter::Base) and route log messages from one or more categories to it. .SH ADAPTERS .IX Header "ADAPTERS" In order to use a logging mechanism with \f(CW\*(C`Log::Any\*(C'\fR, there needs to be an adapter class for it. Typically this is named Log::Any::Adapter::\fIsomething\fR. .SS "Adapters in this distribution" .IX Subsection "Adapters in this distribution" Three basic adapters come with this distribution \-\- Log::Any::Adapter::File, Log::Any::Adapter::Stdout and Log::Any::Adapter::Stderr: .PP .Vb 3 \& use Log::Any::Adapter (\*(AqFile\*(Aq, \*(Aq/path/to/file.log\*(Aq); \& use Log::Any::Adapter (\*(AqStdout\*(Aq); \& use Log::Any::Adapter (\*(AqStderr\*(Aq); \& \& # or \& \& use Log::Any::Adapter; \& Log::Any::Adapter\->set(\*(AqFile\*(Aq, \*(Aq/path/to/file.log\*(Aq); \& Log::Any::Adapter\->set(\*(AqStdout\*(Aq); \& Log::Any::Adapter\->set(\*(AqStderr\*(Aq); .Ve .PP All of them simply output the message and newline to the specified destination; a datestamp prefix is added in the \f(CW\*(C`File\*(C'\fR case. For anything more complex you'll want to use a more robust adapter from CPAN. .SS "Adapters on CPAN" .IX Subsection "Adapters on CPAN" A sampling of adapters available on CPAN as of this writing: .IP \(bu 4 Log::Any::Adapter::Log4perl .IP \(bu 4 Log::Any::Adapter::Dispatch .IP \(bu 4 Log::Any::Adapter::FileHandle .IP \(bu 4 Log::Any::Adapter::Syslog .PP You may find other adapters on CPAN by searching for "Log::Any::Adapter", or create your own adapter. See Log::Any::Adapter::Development for more information on the latter. .SH "SETTING AND REMOVING ADAPTERS" .IX Header "SETTING AND REMOVING ADAPTERS" .IP "Log::Any::Adapter\->set ([options, ]adapter_name, adapter_params...)" 4 .IX Item "Log::Any::Adapter->set ([options, ]adapter_name, adapter_params...)" This method sets the adapter to use for all log categories, or for a particular set of categories. .Sp \&\fIadapter_name\fR is the name of an adapter. It is automatically prepended with "Log::Any::Adapter::". If instead you want to pass the full name of an adapter, prefix it with a "+". e.g. .Sp .Vb 2 \& # Use My::Adapter class \& Log::Any::Adapter\->set(\*(Aq+My::Adapter\*(Aq, arg => $value); .Ve .Sp \&\fIadapter_params\fR are passed along to the adapter constructor. See the documentation for the individual adapter classes for more information. .Sp An optional hash of \fIoptions\fR may be passed as the first argument. Options are: .RS 4 .IP category 4 .IX Item "category" A string containing a category name, or a regex (created with \f(CW\*(C`qr//\*(C'\fR) matching multiple categories. If not specified, all categories will be routed to the adapter. .IP lexically 4 .IX Item "lexically" A reference to a lexical variable. When the variable goes out of scope, the adapter setting will be removed. e.g. .Sp .Vb 2 \& { \& Log::Any::Adapter\->set({lexically => \emy $lex}, ...); \& \& # in effect here \& ... \& } \& # no longer in effect here .Ve .RE .RS 4 .Sp \&\f(CW\*(C`set\*(C'\fR returns an entry object, which can be passed to \f(CW\*(C`remove\*(C'\fR. If you call \f(CW\*(C`set\*(C'\fR repeatedly without calling \f(CW\*(C`remove\*(C'\fR you will leak memory. For most programs that set an adapter once until the end of the program, this shouldn't matter. .RE .IP "use Log::Any::Adapter (...)" 4 .IX Item "use Log::Any::Adapter (...)" If you pass arguments to \f(CW\*(C`use Log::Any::Adapter\*(C'\fR, it calls \f(CW\*(C`Log::Any::Adapter\->set\*(C'\fR with those arguments. .IP "Log::Any::Adapter\->remove (entry)" 4 .IX Item "Log::Any::Adapter->remove (entry)" Remove an \fIentry\fR previously returned by \f(CW\*(C`set\*(C'\fR. .SH "USING MORE THAN ONE ADAPTER" .IX Header "USING MORE THAN ONE ADAPTER" \&\f(CW\*(C`Log::Any\*(C'\fR maintains a stack of entries created via \f(CW\*(C`set\*(C'\fR. If you call \&\f(CW\*(C`set\*(C'\fR repeatedly, you will leak memory unless you do one of the following: .PP When getting a logger for a particular category, \f(CW\*(C`Log::Any\*(C'\fR will work its way down the stack and use the first matching entry. .PP Whenever the stack changes, any \f(CW\*(C`Log::Any\*(C'\fR loggers that have previously been created will automatically adjust to the new stack. For example: .PP .Vb 9 \& my $log = Log::Any\->get_logger(); \& $log\->error("aiggh!"); # this goes nowhere \& ... \& { \& Log::Any::Adapter\->set({ lexically => \emy $lex }, \*(AqLog4perl\*(Aq); \& $log\->error("aiggh!"); # this goes to log4perl \& ... \& } \& $log\->error("aiggh!"); # this goes nowhere again .Ve .SH "BUILDING ON THE Log::Any BACKEND" .IX Header "BUILDING ON THE Log::Any BACKEND" .IP get 4 .IX Item "get" .Vb 1 \& my $adapter= Log::Any::Adapter\->get($category); .Ve .Sp The primary intended way to extend the producing-side of Log::Any is with a custom Log::Any::Proxy class. However, for special logging scenarios you might also just want access to the adapter for a given category. The API of an adapter object is described in Log::Any::Adapter::Development. Beware that adapter objects can be "rewritten" on the fly, so any conditional behavior you write depending on the capabilities of an adapter must be re-checked every time you access the adapter. .SH "SEE ALSO" .IX Header "SEE ALSO" Log::Any .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.