line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::Mojo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
1
|
|
|
1
|
|
975
|
$Log::Any::Adapter::Mojo::VERSION = '0.06'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
8
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
9
|
1
|
|
|
1
|
|
1071
|
use Log::Any::Adapter::Util qw(make_method); |
|
1
|
|
|
|
|
881
|
|
|
1
|
|
|
|
|
82
|
|
10
|
1
|
|
|
1
|
|
7
|
use base qw(Log::Any::Adapter::Base); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1242
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
3170
|
use Mojo::Log; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init { |
15
|
2
|
|
|
2
|
0
|
12399
|
my ($self) = @_; |
16
|
2
|
|
33
|
|
|
19
|
$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
|
1
|
|
|
1
|
|
1005
|
my $self = shift; |
37
|
1
|
|
|
|
|
5
|
my ( $pkg, $line ) = ( caller() )[ 0, 2 ]; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Quick and dirty hack to get correct package and line number |
40
|
|
|
|
|
|
|
# into log line. |
41
|
1
|
|
|
1
|
|
336
|
no warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1082
|
|
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
3
|
my $old_syswrite = *{*IO::Handle::syswrite}{CODE}; |
|
1
|
|
|
|
|
48
|
|
44
|
|
|
|
|
|
|
local *IO::Handle::syswrite = sub { |
45
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
46
|
0
|
|
|
|
|
0
|
my $l = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$l =~ s/Log::Any::Adapter::Mojo:\d+/\Q$pkg\E:\Q$line\E/; |
49
|
0
|
|
|
|
|
0
|
$l =~ s/Mojo::EventEmitter:\d+/\Q$pkg\E:\Q$line\E/; |
50
|
0
|
|
|
|
|
0
|
$l =~ s/Mojo::Log:\d+/\Q$pkg\E:\Q$line\E/; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
return $self->$old_syswrite( $l, @_ ); |
53
|
1
|
|
|
|
|
39
|
}; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
21
|
return $self->{logger}->$mojo_method(@_); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Create detection methods: is_debug, is_info, etc. |
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
foreach my $method ( Log::Any->detection_methods ) { |
63
|
|
|
|
|
|
|
my $mojo_method = $method; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Map log levels down to Mojo::Log levels where necessary |
66
|
|
|
|
|
|
|
# |
67
|
|
|
|
|
|
|
for ($mojo_method) { |
68
|
|
|
|
|
|
|
s/trace/debug/; |
69
|
|
|
|
|
|
|
s/notice/info/; |
70
|
|
|
|
|
|
|
s/warning/warn/; |
71
|
|
|
|
|
|
|
s/critical|alert|emergency/fatal/; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
make_method( |
75
|
|
|
|
|
|
|
$method, |
76
|
|
|
|
|
|
|
sub { |
77
|
0
|
|
|
0
|
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
return $self->{logger}->$mojo_method(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |