Acme-Beamerang-Logger
view release on metacpan or search on metacpan
lib/Acme/Beamerang/Logger.pm view on Meta::CPAN
use 5.006; # our
use strict;
use warnings;
package Acme::Beamerang::Logger;
our $VERSION = '0.001000';
use parent 'Log::Contextual';
sub default_import { qw(:dlog :log ) }
# This ideally would be regulated by the importing class
# but I got tired of trying to guess what horrible magic
# was necessary to make Exporter::Declare and whatever
# the hell Log::Contextual's import logic does work.
sub _get_prefixes {
my $class = $_[0];
my (@parts) = split /::/sx, $class;
# Always assume there is no Acme
# Acme::X is X in the future.
shift @parts if $parts[0] eq 'Acme';
my (@prefixes);
# Always include FQ name, sans Acme
push @prefixes, uc( join q/_/, @parts );
pop @parts;
# If its a Beamerang subclass, split the namespace
# and create env vars for each level.
if ( 2 <= @parts and ( 'Beamerang' eq shift @parts ) ) {
while (@parts) {
push @prefixes, uc( join q/_/, 'BEAMERANG', @parts );
pop @parts;
}
}
return @prefixes, 'BEAMERANG';
}
sub arg_default_logger {
return $_[1] if $_[1];
require Log::Contextual::WarnLogger::Fancy;
my $caller = caller(3);
my ( $env, @group ) = _get_prefixes($caller);
return Log::Contextual::WarnLogger::Fancy->new(
{
env_prefix => $env,
group_env_prefix => \@group,
label => $caller,
label_length => 21,
default_upto => 'warn',
}
);
}
1;
=head1 NAME
Acme::Beamerang::Logger - A Simple per-class clan warnlogger loader
=head1 SYNOPSIS
# Interface is basically the same as Log::Contextual::Easy::Default
use Acme::Beamerang::Logger; # imports :dlog and :log by default
# also assigns a default logger to the package.
( run in 4.604 seconds using v1.01-cache-2.11-cpan-364913b4093 )