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.9911';
4              
5 2     2   7135 use strict; use warnings;
  2     2   4  
  2         55  
  2         9  
  2         5  
  2         74  
6             #use Dancer2 qw/ !log !debug !info !notice !warning !error /;
7 2     2   422 use Dancer2::Core::Types qw/ Str ArrayRef /;
  2         139389  
  2         26  
8              
9 2     2   3383 use Log::Any::Adapter;
  2         6779  
  2         11  
10              
11 2     2   414 use Moo;
  2         7571  
  2         14  
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   28 my $self = shift;
20              
21 1 50       8 my %category = $self->category ?
22             ( category => $self->category ) : ();
23              
24 1         2 Log::Any::Adapter->set( @{ $self->logger } );
  1         13  
25 1         175 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__