line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Log::Fast; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
112714
|
use Mojo::Base 'Mojo::Log'; |
|
2
|
|
|
|
|
216826
|
|
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
45709
|
use Carp 'croak'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
98
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 'v1.0.1'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
848
|
use Log::Fast; |
|
2
|
|
|
|
|
39653
|
|
|
2
|
|
|
|
|
1011
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %MapLevel = ( |
12
|
|
|
|
|
|
|
debug => 'DEBUG', |
13
|
|
|
|
|
|
|
info => 'INFO', |
14
|
|
|
|
|
|
|
warn => 'WARN', |
15
|
|
|
|
|
|
|
error => 'ERR', |
16
|
|
|
|
|
|
|
fatal => 'ERR', |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
0
|
|
|
0
|
1
|
|
my $self = shift->SUPER::new(); |
22
|
0
|
|
0
|
|
|
|
$self->{'_logger'} = shift || Log::Fast->global(); |
23
|
0
|
0
|
|
|
|
|
if ($ENV{MOJO_LOG_LEVEL}) { |
24
|
0
|
|
|
|
|
|
$self->level($ENV{MOJO_LOG_LEVEL}); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
0
|
|
|
|
|
|
$self->level({reverse %MapLevel}->{ $self->{_logger}->level }); |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
$self->unsubscribe('message'); |
30
|
0
|
|
|
|
|
|
$self->on(message => \&_message); |
31
|
0
|
|
|
|
|
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
1
|
|
sub config { return shift->{'_logger'}->config(@_); } |
35
|
0
|
|
|
0
|
1
|
|
sub ident { return shift->{'_logger'}->ident(@_); } |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
|
sub handle { croak q{log->handle: not supported, use log->config} }; |
38
|
0
|
|
|
0
|
1
|
|
sub path { croak q{log->path: not supported, use log->config} }; |
39
|
0
|
|
|
0
|
1
|
|
sub format { croak q{log->format: not implemented} }; ## no critic(ProhibitBuiltinHomonyms) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub level { |
42
|
0
|
0
|
|
0
|
1
|
|
if (@_ == 1) { |
43
|
0
|
0
|
|
|
|
|
return $_[0]{'level'} if exists $_[0]{'level'}; |
44
|
0
|
|
|
|
|
|
return $_[0]{'level'} = 'debug'; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
0
|
|
|
|
$_[0]{'level'} = $ENV{MOJO_LOG_LEVEL} || $_[1]; |
47
|
0
|
|
0
|
|
|
|
$_[0]{'_logger'}->level($MapLevel{ $ENV{MOJO_LOG_LEVEL} || $_[1] }); |
48
|
0
|
|
|
|
|
|
return $_[0]; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _message { |
52
|
0
|
|
|
0
|
|
|
my ($self, $level, @lines) = @_; |
53
|
0
|
0
|
|
|
|
|
if ($level eq 'debug') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$self->{'_logger'}->DEBUG(join "\n", @lines); |
55
|
|
|
|
|
|
|
} elsif ($level eq 'info') { |
56
|
0
|
|
|
|
|
|
$self->{'_logger'}->INFO(join "\n", @lines); |
57
|
|
|
|
|
|
|
} elsif ($level eq 'warn') { |
58
|
0
|
|
|
|
|
|
$self->{'_logger'}->WARN(join "\n", @lines); |
59
|
|
|
|
|
|
|
} else { # error, fatal |
60
|
0
|
|
|
|
|
|
$self->{'_logger'}->ERR(join "\n", @lines); |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
66
|
|
|
|
|
|
|
__END__ |