line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::MojoLog; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
395930
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
365
|
use Log::Any::Adapter::Util qw(make_method); |
|
1
|
|
|
|
|
6257
|
|
|
1
|
|
|
|
|
38
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Log::Any::Adapter::Base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
358
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
445
|
use Mojo::Log; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init { |
15
|
1
|
|
|
1
|
0
|
276
|
my ($self) = @_; |
16
|
1
|
|
33
|
|
|
7
|
$self->{logger} ||= Mojo::Log->new; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Create logging methods |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
foreach my $method ( Log::Any->logging_methods ) { |
22
|
|
|
|
|
|
|
my $mojo_method = $method; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Map log levels down to Mojo::Log levels where necessary |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
for ($mojo_method) { |
27
|
|
|
|
|
|
|
s/trace/debug/; |
28
|
|
|
|
|
|
|
s/notice/info/; |
29
|
|
|
|
|
|
|
s/warning/warn/; |
30
|
|
|
|
|
|
|
s/critical|alert|emergency/fatal/; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
make_method( |
34
|
|
|
|
|
|
|
$method, |
35
|
|
|
|
|
|
|
sub { |
36
|
9
|
|
|
9
|
|
225
|
my $self = shift; |
37
|
9
|
|
|
|
|
29
|
return $self->{logger}->$mojo_method(@_); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Create detection methods: is_debug, is_info, etc. |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $true = sub { 1 }; |
46
|
|
|
|
|
|
|
foreach my $method ( Log::Any->detection_methods ) { |
47
|
|
|
|
|
|
|
my $mojo_method = $method; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Map log levels down to Mojo::Log levels where necessary |
50
|
|
|
|
|
|
|
# |
51
|
|
|
|
|
|
|
for ($mojo_method) { |
52
|
|
|
|
|
|
|
s/trace/debug/; |
53
|
|
|
|
|
|
|
s/notice/info/; |
54
|
|
|
|
|
|
|
s/warning/warn/; |
55
|
|
|
|
|
|
|
s/critical|alert|emergency/fatal/; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $level; |
59
|
|
|
|
|
|
|
if ($mojo_method eq 'is_fatal') { |
60
|
|
|
|
|
|
|
# is_fatal has been removed since 6.0, it was always true |
61
|
|
|
|
|
|
|
$mojo_method = $true; |
62
|
|
|
|
|
|
|
} elsif (eval { require Mojolicious; Mojolicious->VERSION('6.47'); 1 }) { |
63
|
|
|
|
|
|
|
# as of 6.47 the is_* methods have been removed in favor of |
64
|
|
|
|
|
|
|
# is_level($level) |
65
|
|
|
|
|
|
|
($level = $mojo_method) =~ s/^is_//; |
66
|
|
|
|
|
|
|
$mojo_method = 'is_level'; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
make_method( |
70
|
|
|
|
|
|
|
$method, |
71
|
|
|
|
|
|
|
sub { |
72
|
27
|
|
|
27
|
|
8977
|
my $self = shift; |
73
|
27
|
100
|
|
|
|
90
|
return $self->{logger}->$mojo_method($level ? $level : ()); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |