line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Log::Fast; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
142278
|
use Mojo::Base 'Mojo::Log'; |
|
2
|
|
|
|
|
414863
|
|
|
2
|
|
|
|
|
19
|
|
4
|
2
|
|
|
2
|
|
103770
|
use Carp 'croak'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
132
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 'v1.2.0'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1289
|
use Log::Fast; |
|
2
|
|
|
|
|
45270
|
|
|
2
|
|
|
|
|
1663
|
|
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
|
|
|
|
|
|
|
sub context { |
35
|
0
|
|
|
0
|
1
|
|
my ($parent, @context) = @_; |
36
|
0
|
|
|
|
|
|
my $self = $parent->new(); |
37
|
0
|
|
|
|
|
|
$self->level($parent->level); |
38
|
0
|
|
|
|
|
|
$self->{'context'} = \@context; |
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
0
|
1
|
|
sub config { return shift->{'_logger'}->config(@_); } |
43
|
0
|
|
|
0
|
1
|
|
sub ident { return shift->{'_logger'}->ident(@_); } |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
1
|
|
sub handle { croak q{log->handle: not supported, use log->config} }; |
46
|
0
|
|
|
0
|
1
|
|
sub path { croak q{log->path: not supported, use log->config} }; |
47
|
0
|
|
|
0
|
1
|
|
sub format { croak q{log->format: not implemented} }; ## no critic(ProhibitBuiltinHomonyms) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub level { |
50
|
0
|
0
|
|
0
|
1
|
|
if (@_ == 1) { |
51
|
0
|
0
|
|
|
|
|
return $_[0]{'level'} if exists $_[0]{'level'}; |
52
|
0
|
|
|
|
|
|
return $_[0]{'level'} = 'debug'; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
0
|
|
|
|
$_[0]{'level'} = $ENV{MOJO_LOG_LEVEL} || $_[1]; |
55
|
0
|
|
0
|
|
|
|
$_[0]{'_logger'}->level($MapLevel{ $ENV{MOJO_LOG_LEVEL} || $_[1] }); |
56
|
0
|
|
|
|
|
|
return $_[0]; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _message { |
60
|
0
|
|
|
0
|
|
|
my ($self, $level, @lines) = @_; |
61
|
0
|
0
|
|
|
|
|
if ($self->{'context'}) { |
62
|
0
|
|
|
|
|
|
unshift @lines, @{$self->{context}} |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
0
|
0
|
|
|
|
|
if ($level eq 'debug') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->{'_logger'}->DEBUG(join q{ }, @lines); |
66
|
|
|
|
|
|
|
} elsif ($level eq 'info') { |
67
|
0
|
|
|
|
|
|
$self->{'_logger'}->INFO(join q{ }, @lines); |
68
|
|
|
|
|
|
|
} elsif ($level eq 'warn') { |
69
|
0
|
|
|
|
|
|
$self->{'_logger'}->WARN(join q{ }, @lines); |
70
|
|
|
|
|
|
|
} else { # error, fatal |
71
|
0
|
|
|
|
|
|
$self->{'_logger'}->ERR(join q{ }, @lines); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
77
|
|
|
|
|
|
|
__END__ |