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.9912';
4              
5 2     2   9417 use strict; use warnings;
  2     2   44  
  2         100  
  2         18  
  2         6  
  2         119  
6             #use Dancer2 qw/ !log !debug !info !notice !warning !error /;
7 2     2   738 use Dancer2::Core::Types qw/ Str ArrayRef /;
  2         248832  
  2         37  
8              
9 2     2   5030 use Log::Any::Adapter;
  2         11487  
  2         13  
10              
11 2     2   675 use Moo;
  2         12774  
  2         20  
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   44 my $self = shift;
20              
21 1 50       13 my %category = $self->category ?
22             ( category => $self->category ) : ();
23              
24 1         3 Log::Any::Adapter->set( @{ $self->logger } );
  1         20  
25 1         313 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__