VERSION

version 0.11

SYNOPSIS

    # Log to a file, or stdout, or stderr for all categories
    #
    use Log::Any::Adapter ('File', '/path/to/file.log');
    use Log::Any::Adapter ('Stdout');
    use Log::Any::Adapter ('Stderr');

    # Use Log::Log4perl for all categories
    #
    Log::Log4perl::init('/etc/log4perl.conf');
    Log::Any::Adapter->set('Log4perl');

    # Use Log::Dispatch for Foo::Baz
    #
    use Log::Dispatch;
    my $log = Log::Dispatch->new(outputs => [[ ... ]]);
    Log::Any::Adapter->set( { category => 'Foo::Baz' },
        'Dispatch', dispatcher => $log );

    # Use Log::Dispatch::Config for Foo::Baz and its subcategories
    #
    use Log::Dispatch::Config;
    Log::Dispatch::Config->configure('/path/to/log.conf');
    Log::Any::Adapter->set(
        { category => qr/^Foo::Baz/ },
        'Dispatch', dispatcher => Log::Dispatch::Config->instance() );

    # Use your own adapter for all categories
    #
    Log::Any::Adapter->set('+My::Log::Any::Adapter', ...);

DESCRIPTION

The \*(C`Log-Any-Adapter\*(C' distribution implements Log::Any class methods to specify where logs should be sent. It is a separate distribution so as to keep \*(C`Log::Any\*(C' itself as simple and unchanging as possible.

You do not have to use anything in this distribution explicitly. It will be auto-loaded when you call one of the methods below.

ADAPTERS

In order to use a logging mechanism with \*(C`Log::Any\*(C', there needs to be an adapter class for it. Typically this is named Log::Any::Adapter::something.

Adapters in this distribution

Three basic adapters come with this distribution \*(-- File, Stdout and Stderr:

use Log::Any::Adapter ('File', '/path/to/file.log'); use Log::Any::Adapter ('Stdout'); use Log::Any::Adapter ('Stderr');

# or

use Log::Any::Adapter; Log::Any::Adapter->set('File', '/path/to/file.log'); Log::Any::Adapter->set('Stdout'); Log::Any::Adapter->set('Stderr');

All of them simply output the message and newline to the specified destination; a datestamp prefix is added in the \*(C`File\*(C' case. For anything more complex you'll want to use a more robust adapter from \s-1CPAN\s0.

Adapters on \s-1CPAN\s0

A sampling of adapters available on \s-1CPAN\s0 as of this writing:

  • Log::Any::Adapter::Log4perl

  • Log::Any::Adapter::Dispatch

  • Log::Any::Adapter::FileHandle

  • Log::Any::Adapter::Syslog

You may find other adapters on \s-1CPAN\s0 by searching for \*(L"Log::Any::Adapter\*(R", or create your own adapter. See Log::Any::Adapter::Development for more information on the latter.

SETTING AND REMOVING ADAPTERS

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. adapter_name is the name of an adapter. It is automatically prepended with \*(L"Log::Any::Adapter::\*(R". If instead you want to pass the full name of an adapter, prefix it with a \*(L"+\*(R". e.g. # Use My::Adapter class Log::Any::Adapter->set('+My::Adapter', arg => $value); adapter_params are passed along to the adapter constructor. See the documentation for the individual adapter classes for more information. An optional hash of options may be passed as the first argument. Options are:

category

A string containing a category name, or a regex (created with qr//) matching multiple categories. If not specified, all categories will be affected.

lexically

A reference to a lexical variable. When the variable goes out of scope, the adapter setting will be removed. e.g. { Log::Any::Adapter->set({lexically => \my $lex}, ...);

# in effect here ... } # no longer in effect here

\*(C`set\*(C' returns an entry object, which can be passed to \*(C`remove\*(C'.

use Log::Any::Adapter (...)

If you pass arguments to \*(C`use Log::Any::Adapter\*(C', it calls \*(C`Log::Any::Adapter->set\*(C' with those arguments.

Log::Any::Adapter->remove (entry)

Remove an entry previously returned by \*(C`set\*(C'.

MULTIPLE ADAPTER SETTINGS

\*(C`Log::Any\*(C' maintains a stack of entries created via \*(C`set\*(C'.

When you get a logger for a particular category, \*(C`Log::Any\*(C' will work its way down the stack and use the first matching entry.

Whenever the stack changes, any \*(C`Log::Any\*(C' loggers that have previously been created will automatically adjust to the new stack. For example:

my $log = Log::Any->get_logger(); $log->error("aiggh!"); # this goes nowhere ... { Log::Any::Adapter->set({ lexically => \my $lex }, 'Log4perl'); $log->error("aiggh!"); # this goes to log4perl ... } $log->error("aiggh!"); # this goes nowhere again

RELATED TO Log::Any::Adapter…

Log::Any

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Jonathan Swartz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.