line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Log::Fast; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
147454
|
use Mojo::Base 'Mojo::Log'; |
|
2
|
|
|
|
|
415300
|
|
|
2
|
|
|
|
|
17
|
|
4
|
2
|
|
|
2
|
|
102011
|
use Carp 'croak'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
146
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 'v1.1.0'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1349
|
use Log::Fast; |
|
2
|
|
|
|
|
44872
|
|
|
2
|
|
|
|
|
1715
|
|
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, $str) = @_; |
36
|
0
|
|
|
|
|
|
my $self = $parent->new(); |
37
|
0
|
|
|
|
|
|
$self->level($parent->level); |
38
|
0
|
|
|
|
|
|
$self->{'context'} = $str; |
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
|
|
|
|
|
|
$lines[0] = "$self->{context} $lines[0]"; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
0
|
|
|
|
|
if ($level eq 'debug') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->{'_logger'}->DEBUG(join "\n", @lines); |
66
|
|
|
|
|
|
|
} elsif ($level eq 'info') { |
67
|
0
|
|
|
|
|
|
$self->{'_logger'}->INFO(join "\n", @lines); |
68
|
|
|
|
|
|
|
} elsif ($level eq 'warn') { |
69
|
0
|
|
|
|
|
|
$self->{'_logger'}->WARN(join "\n", @lines); |
70
|
|
|
|
|
|
|
} else { # error, fatal |
71
|
0
|
|
|
|
|
|
$self->{'_logger'}->ERR(join "\n", @lines); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
77
|
|
|
|
|
|
|
__END__ |