Acme-Beamerang-Logger
view release on metacpan or search on metacpan
{
"abstract" : "A Simple per-class clan warnlogger loader",
"author" : [
"Kent Fredric <kentnl@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "App::ModuleBuildTiny version 0.013",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'A Simple per-class clan warnlogger loader'
author:
- 'Kent Fredric <kentnl@cpan.org>'
build_requires:
Term::ANSIColor: '2.01'
Test::More: '0.88'
configure_requires:
Module::Build::Tiny: '0.034'
dynamic_config: 0
generated_by: 'App::ModuleBuildTiny version 0.013, CPAN::Meta::Converter version 2.150005'
license: perl
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);
lib/Acme/Beamerang/Logger.pm view on Meta::CPAN
# 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.
=head1 DESCRIPTION
This class is a convenience layer to tie L<Log::Contextual::WarnLogger::Fancy>
into the C<Acme::Beamerang> project space.
This is very experiemental and is a research project ( hence C<Acme::> ).
This would otherwise be part of the other C<Acme::Beamerang> things that are still yet to
materialise, but the inversion control this project entails means directly coupling
this component with either of those parts would lead to a dependency graph that would
defeat the point of the control inversion.
This tool otherwise loads up C<Log::Contextual> with a nice default logger, with all the glue
in place to be convenient for this project, while still having an open door to a real logger.
=head1 ENVIRONMENT
This module utilizes the C<env_prefix> and C<group_env_prefix> of L<Log::Contextual::WarnLogger::Fancy>
to generate a collection of C<ENV> vars for narrow or broad incision of logging statements without need
to use more complex logging technology.
Every package that uses this logger will respond to C<BEAMERANG_$LOG_LEVEL> and C<BEAMERANG_UPTO> values.
Every package beginning with either C<Acme::Beamerang::> or C<Beamerang::> will additionally respond to
a collection of namespace oriented C<ENV> variables.
For instance,
Acme::Beamerang::Foo::Bar::Baz
Will respond to any of the following C<ENV> vars:
lib/Acme/Beamerang/Logger.pm view on Meta::CPAN
So C<Beamerang> is a mutant hybrid of the above.
Other parts of this system that have yet to manifest will use the same convention.
=head1 SEE ALSO
=over 4
=item * L<< C<Log::Contextual::Easy::Default>|Log::Contextual::Easy::Default >> - Interface is otherwise identical to this
module, only the default logger in choice and its configuration differs.
=back
=head1 AUTHOR
Kent Fredric <kentnl@cpan.org>
=head1 LICENSE
This software is copyright (c) 2016 by Kent Fredric.
t/basic-noacme.t view on Meta::CPAN
use Test::More;
use Term::ANSIColor qw( colorstrip );
{
package # Hide from indexers
Beamerang::KENTNL::Example;
use Acme::Beamerang::Logger;
sub do_work {
log_warn { "This is a warning" };
log_trace { "This is a trace" };
}
}
my $capture = '';
{
my %old = %ENV;
delete $old{$_} for grep /BEAMERANG/, keys %old;
local (%ENV) = (%old);
local $SIG{__WARN__} = sub { $capture .= colorstrip( $_[0] ) };
Beamerang::KENTNL::Example->do_work;
t/basic-nobeamerang.t view on Meta::CPAN
use Test::More;
use Term::ANSIColor qw( colorstrip );
{
package # Hide from indexers
KENTNL::Example;
use Acme::Beamerang::Logger;
sub do_work {
log_warn { "This is a warning" };
log_trace { "This is a trace" };
}
}
my $capture = '';
{
my %old = %ENV;
delete $old{$_} for grep /BEAMERANG/, keys %old;
local (%ENV) = (%old);
local $SIG{__WARN__} = sub { $capture .= colorstrip($_[0]) };
KENTNL::Example->do_work;
t/basic-short.t view on Meta::CPAN
use Test::More;
use Term::ANSIColor qw( colorstrip );
{
package # Hide from indexers
Beamerang;
use Acme::Beamerang::Logger;
sub do_work {
log_warn { "This is a warning" };
log_trace { "This is a trace" };
}
}
my $capture = '';
{
my %old = %ENV;
delete $old{$_} for grep /BEAMERANG/, keys %old;
local (%ENV) = (%old);
local $SIG{__WARN__} = sub { $capture .= colorstrip($_[0]) };
Beamerang->do_work;
use Test::More;
use Term::ANSIColor qw( colorstrip );
{
package # Hide from indexers
Acme::Beamerang::KENTNL::Example;
use Acme::Beamerang::Logger;
sub do_work {
log_warn { "This is a warning" };
log_trace { "This is a trace" };
}
}
my $capture = '';
{
my %old = %ENV;
delete $old{$_} for grep /BEAMERANG/, keys %old;
local (%ENV) = (%old);
local $SIG{__WARN__} = sub { $capture .= colorstrip( $_[0] ) };
Acme::Beamerang::KENTNL::Example->do_work;
( run in 1.491 second using v1.01-cache-2.11-cpan-49f99fa48dc )