File Coverage

blib/lib/Ark/Logger.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 6 7 85.7
pod 0 1 0.0
total 27 30 90.0


line stmt bran cond sub pod time code
1             package Ark::Logger;
2 60     60   26454 use Mouse;
  60         130  
  60         353  
3 60     60   20763 use utf8;
  60         148  
  60         368  
4              
5             has log_level => (
6             is => 'rw',
7             isa => 'Str',
8             default => $ENV{ARK_DEBUG} ? 'debug' : 'error',
9             );
10              
11             has log_levels => (
12             is => 'rw',
13             isa => 'HashRef',
14             default => sub {
15             { debug => 4,
16             info => 3,
17             warn => 2,
18             error => 1,
19             fatal => 0,
20             };
21             },
22             );
23              
24 60     60   6704 no Mouse;
  60         173  
  60         316  
25              
26             {
27 60     60   7927 no strict 'refs';
  60         126  
  60         16456  
28             my $pkg = __PACKAGE__;
29             for my $level (qw/debug info warn error fatal/) {
30             *{"${pkg}::${level}"} = sub {
31 2     2   5 my ($self, $msg, @args) = @_;
        0      
32 2         88 print STDERR sprintf("[%s] $msg\n", $level, @args);
33             };
34             }
35             }
36              
37             sub log {
38 362     362 0 1336 my ($self, $type, $msg, @args) = @_;
39              
40             return if !$self->log_levels->{$type}
41 362 100 66     3708 or $self->log_levels->{$type} > $self->log_levels->{ $self->log_level };
42              
43 4         245 print STDERR sprintf("[%s] ${msg}\n", $type, @args);
44             }
45              
46             __PACKAGE__->meta->make_immutable;
47