File Coverage

blib/lib/Dancer2/Logger/LogAny.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 27 28 96.4


line stmt bran cond sub pod time code
1             package Dancer2::Logger::LogAny;
2              
3             our $VERSION = '0.9910';
4              
5 2     2   6625 use strict; use warnings;
  2     2   4  
  2         48  
  2         8  
  2         3  
  2         51  
6             #use Dancer2 qw/ !log !debug !info !notice !warning !error /;
7 2     2   251 use Dancer2::Core::Types qw/ Str ArrayRef /;
  2         116070  
  2         23  
8              
9 2     2   3133 use Log::Any::Adapter;
  2         6388  
  2         8  
10              
11 2     2   366 use Moo;
  2         7275  
  2         9  
12             with 'Dancer2::Core::Role::Logger';
13              
14             has category => ( is => 'ro', isa => Str );
15             has logger => ( is => 'ro', isa => ArrayRef, required => 1 );
16             has _logger_obj => ( is => 'lazy' );
17              
18             sub _build__logger_obj {
19 1     1   25 my $self = shift;
20              
21 1 50       8 my %category = $self->category ?
22             ( category => $self->category ) : ();
23              
24 1         3 Log::Any::Adapter->set( @{ $self->logger } );
  1         10  
25 1         177 return Log::Any->get_logger( %category );
26             }
27              
28             sub log {
29             my ( $self, $level, $message ) = @_;
30              
31             $level = 'debug' if $level eq 'core';
32              
33             $self->_logger_obj->$level( $message );
34             }
35              
36             1; # return true
37              
38             __END__