| Log-Any-Adapter-Dispatch documentation | Contained in the Log-Any-Adapter-Dispatch distribution. |
Log::Any::Adapter::Dispatch
use Log::Any::Adapter;
Log::Any::Adapter->set('Dispatch', outputs => [[ ... ]]);
my $dispatcher = Log::Dispatch->new( ... );
Log::Any::Adapter->set('Dispatch', dispatcher => $dispatcher);
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.
Jonathan Swartz
Copyright (C) 2007 Jonathan Swartz, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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__