Log-Dispatchouli
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Log/Dispatchouli/Proxy.pm view on Meta::CPAN
use v5.20;
use warnings;
package Log::Dispatchouli::Proxy 3.007;
# ABSTRACT: a simple wrapper around Log::Dispatch
use experimental 'postderef'; # Not dangerous. Is accepted without changed.
use Log::Fmt ();
use Params::Util qw(_ARRAY0 _HASH0);
#pod =head1 DESCRIPTION
#pod
#pod A Log::Dispatchouli::Proxy object is the child of a L<Log::Dispatchouli> logger
#pod (or another proxy) and relays log messages to its parent. It behaves almost
#pod identically to a Log::Dispatchouli logger, and you should refer there for more
#pod of its documentation.
#pod
#pod Here are the differences:
#pod
#pod =begin :list
#pod
#pod * You can't create a proxy with C<< ->new >>, only by calling C<< ->proxy >> on an existing logger or proxy.
#pod
#pod * C<set_debug> will set a value for the proxy; if none is set, C<get_debug> will check the parent's setting; C<clear_debug> will clear any set value on this proxy
#pod
#pod * C<log_debug> messages will be redispatched to C<log> (to the 'debug' logging level) to prevent parent loggers from dropping them due to C<debug> setting differences
#pod
#pod =end :list
#pod
#pod =cut
sub _new {
my ($class, $arg) = @_;
my $guts = {
parent => $arg->{parent},
logger => $arg->{logger},
debug => $arg->{debug},
proxy_prefix => $arg->{proxy_prefix},
proxy_ctx => $arg->{proxy_ctx},
};
bless $guts => $class;
}
sub proxy {
my ($self, $arg) = @_;
$arg ||= {};
my @proxy_ctx;
if (my $ctx = $arg->{proxy_ctx}) {
@proxy_ctx = _ARRAY0($ctx)
? (@proxy_ctx, @$ctx)
: (@proxy_ctx, $ctx->%{ sort keys %$ctx });
}
my $prox = (ref $self)->_new({
parent => $self,
logger => $self->logger,
debug => $arg->{debug},
muted => $arg->{muted},
proxy_prefix => $arg->{proxy_prefix},
proxy_ctx => \@proxy_ctx,
});
}
sub parent { $_[0]{parent} }
sub logger { $_[0]{logger} }
sub ident { $_[0]{logger}->ident }
sub config_id { $_[0]{logger}->config_id }
sub set_prefix { $_[0]{prefix} = $_[1] }
sub get_prefix { $_[0]{prefix} }
sub clear_prefix { undef $_[0]{prefix} }
sub unset_prefix { $_[0]->clear_prefix }
sub set_debug { $_[0]{debug} = $_[1] ? 1 : 0 }
sub clear_debug { undef $_[0]{debug} }
sub get_debug {
return $_[0]{debug} if defined $_[0]{debug};
return $_[0]->parent->get_debug;
}
sub is_debug { $_[0]->get_debug }
sub is_info { 1 }
sub is_fatal { 1 }
sub mute { $_[0]{muted} = 1 }
sub unmute { $_[0]{muted} = 0 }
sub set_muted { $_[0]{muted} = $_[1] ? 1 : 0 }
sub clear_muted { undef $_[0]{muted} }
sub _get_local_muted { $_[0]{muted} }
sub get_muted {
return $_[0]{muted} if defined $_[0]{muted};
return $_[0]->parent->get_muted;
}
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.496 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )