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 59     59   36014 use Mouse;
  59         140  
  59         412  
3 59     59   17935 use utf8;
  59         133  
  59         486  
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 59     59   6197 no Mouse;
  59         337  
  59         283  
25              
26             {
27 59     59   6515 no strict 'refs';
  59         317  
  59         15822  
28             my $pkg = __PACKAGE__;
29             for my $level (qw/debug info warn error fatal/) {
30             *{"${pkg}::${level}"} = sub {
31 2     2   6 my ($self, $msg, @args) = @_;
        0      
32 2         89 print STDERR sprintf("[%s] $msg\n", $level, @args);
33             };
34             }
35             }
36              
37             sub log {
38 361     361 0 1491 my ($self, $type, $msg, @args) = @_;
39              
40 361 100 66     5193 return if !$self->log_levels->{$type}
41             or $self->log_levels->{$type} > $self->log_levels->{ $self->log_level };
42              
43 4         484 print STDERR sprintf("[%s] ${msg}\n", $type, @args);
44             }
45              
46             __PACKAGE__->meta->make_immutable;
47