File Coverage

blib/lib/Sentry/Logger.pm
Criterion Covered Total %
statement 37 50 74.0
branch 1 4 25.0
condition 2 3 66.6
subroutine 8 11 72.7
pod 0 5 0.0
total 48 73 65.7


line stmt bran cond sub pod time code
1             package Sentry::Logger;
2 6     6   36 use Mojo::Base -base, -signatures;
  6         14  
  6         70  
3              
4 6     6   2318 use Exporter qw(import);
  6         12  
  6         323  
5 6     6   46 use List::Util 'any';
  6         11  
  6         4419  
6              
7             our @EXPORT_OK = qw(logger);
8              
9             has context => 'Sentry';
10             has active_contexts => sub { [split(/,/, $ENV{DEBUG} // '')] };
11              
12 32     32   41 sub _should_print ($self, $context) {
  32         39  
  32         156  
  32         35  
13 32     0   170 return any { $context =~ $_ } $self->active_contexts->@*;
  0         0  
14             }
15              
16 32     32   40 sub _print ($self, $message, $context, $error = 0) {
  32         43  
  32         40  
  32         43  
  32         45  
  32         39  
17 32 50       71 return unless $self->_should_print($context);
18 0 0       0 print { $error ? *STDERR : *STDOUT } qq{[$context] $message\n};
  0         0  
19             }
20              
21 31     31 0 527 sub log ($self, $message, $context = $self->context) {
  31         56  
  31         45  
  31         43  
  31         54  
22 31         96 $self->_print($message, $context);
23             }
24              
25 0     0 0 0 sub warn ($self, $message, $context = $self->context) {
  0         0  
  0         0  
  0         0  
  0         0  
26 0         0 $self->_print($message, $context, 1);
27             }
28              
29 1     1 0 2 sub error ($self, $message, $context = $self->context) {
  1         1  
  1         2  
  1         4  
  1         10  
30 1         4 $self->_print($message, $context, 1);
31             }
32              
33 0     0 0 0 sub enable ($self) {
  0         0  
  0         0  
34 0         0 $self->enabled(1);
35             }
36              
37             my $Instance;
38              
39 38     38 0 227 sub logger() {
  38         49  
40 38   66     111 $Instance //= Sentry::Logger->new;
41 38         133 return $Instance;
42             }
43              
44             1;