# 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 ...