sedusedan has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I need to temporarily log to an additional Log::Any adapter. Here's an example using Log::Any::Adapter::Callback:

# app.pl use Log::Any '$log'; use Log::Any::Adapter; Log::Any::Adapter->set('Log4perl', some=>'param', ...); # ... if ($some_debugging_flag) { # additionally log to a remote socket Log::Any::Adapter->set( {lexically => \my $lex}, 'CallBack', logging_cb => sub { my ($method, $self, $format, @params) = @_; $socket->print($format, "\r\n"); } ); some_func_which_logs(); } else { # no additional adapter some_func_which_logs(); } # back to normal, logging to Log4perl only ...

What would be the proper way to access the previous adapter inside the logging_cb callback so we can invoke the previous adapter's logging $method too to pass the log message to it? In other words, if $some_debugging_flag is set, during some_func_which_logs() I'd like to log to Log4perl (or whatever the previous adapter is) *and* to a remote socket as well.

Any input appreciated.

Replies are listed 'Best First'.
Re: Log::Any: logging to additional adapter
by swartz (Beadle) on May 16, 2011 at 14:07 UTC
    There is unfortunately no API to do what you want at the moment. Suggestions welcome. It would be pretty easy to write a Log::Any::Adapter::Multiple that delegates to multiple adapters. -Jon (author of Log::Any)

      Thanks for the response. A Log::Any::Adapter::Multiple would not be ideal in my situation, because the previous adapter has been set by other people's code and I still need to access the previous adapter.

      Ignoring this problem for now (during some_func_which_logs() under $some_debugging_flag, previous adapter is not given log messages).