Log::Any::Adapter::Dispatch - Log::Any::Adapter::Dispatch documentation


Log-Any-Adapter-Dispatch documentation Contained in the Log-Any-Adapter-Dispatch distribution.

Index


Code Index:

NAME

Top

Log::Any::Adapter::Dispatch

SYNOPSIS

Top

    use Log::Any::Adapter;

    Log::Any::Adapter->set('Dispatch', outputs => [[ ... ]]);

    my $dispatcher = Log::Dispatch->new( ... );
    Log::Any::Adapter->set('Dispatch', dispatcher => $dispatcher);

DESCRIPTION

Top

This Log::Any adapter uses Log::Dispatch for logging.

You may either pass parameters (like outputs) to be passed to Log::Dispatch->new, or pass a Log::Dispatch object directly in the dispatcher parameter.

SEE ALSO

Top

Log::Any::Adapter, Log::Any, Log::Dispatch

AUTHOR

Top

Jonathan Swartz

COPYRIGHT & LICENSE

Top


Log-Any-Adapter-Dispatch documentation Contained in the Log-Any-Adapter-Dispatch distribution.

package Log::Any::Adapter::Dispatch;
use Log::Any::Adapter::Util qw(make_method);
use Log::Dispatch;
use strict;
use warnings;
use base qw(Log::Any::Adapter::Base);

our $VERSION = '0.06';

sub init {
    my $self = shift;

    # If a dispatcher was not explicitly passed in, create a new one with the passed arguments.
    #
    $self->{dispatcher} ||= Log::Dispatch->new(@_);
}

# Delegate logging methods to same methods in dispatcher
#
foreach my $method ( Log::Any->logging_methods() ) {
    my $log_dispatch_method = $method;
    $log_dispatch_method =~ s/trace/debug/;
    __PACKAGE__->delegate_method_to_slot( 'dispatcher', $method,
        $log_dispatch_method );
}

# Delegate detection methods to would_log
#
foreach my $method ( Log::Any->detection_methods() ) {
    my $level = substr( $method, 3 );
    $level =~ s/trace/debug/;
    make_method( $method,
        sub { my ($self) = @_; return $self->{dispatcher}->would_log($level) }
    );
}

1;

__END__