line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Log::Log4perl; |
2
|
6
|
|
|
6
|
|
395954
|
use Mojo::Base 'Mojo::EventEmitter'; |
|
6
|
|
|
|
|
13651
|
|
|
6
|
|
|
|
|
22
|
|
3
|
6
|
|
|
6
|
|
9381
|
use Log::Log4perl; |
|
6
|
|
|
|
|
201749
|
|
|
6
|
|
|
|
|
22
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
201
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
125
|
|
6
|
6
|
|
|
6
|
|
17
|
use strict; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
1386
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has history => sub { [] }; |
11
|
|
|
|
|
|
|
has max_history_size => 10; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $format_warning_was_shown = 0; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# development notes: Mojo::Log provides 'path' 'handle' and 'format' |
16
|
|
|
|
|
|
|
# to handle log location and formatting. Those make no sense in a Log4perl |
17
|
|
|
|
|
|
|
# environment (where you can set appenders as you wish) so they are |
18
|
|
|
|
|
|
|
# not implemented here; 'format' simply returns the passed-in strings joined by |
19
|
|
|
|
|
|
|
# newlines as otherwise Mojo::Log complains (RT #98034). |
20
|
0
|
|
|
0
|
0
|
0
|
sub path { warn 'path() is not implemented in MojoX::Log::Log4perl. Please use appenders.' } |
21
|
0
|
|
|
0
|
0
|
0
|
sub handle { warn 'handle() is not implemented in MojoX::Log::Log4perl. Please use appenders.' } |
22
|
|
|
|
|
|
|
sub format { |
23
|
0
|
0
|
|
0
|
0
|
0
|
if (!$format_warning_was_shown) { |
24
|
0
|
|
|
|
|
0
|
$format_warning_was_shown = 1; |
25
|
0
|
|
|
|
|
0
|
warn 'format() is not properly implemented in MojoX::Log::Log4perl. Please use appenders.'; |
26
|
|
|
|
|
|
|
} |
27
|
0
|
|
|
0
|
|
0
|
return sub { '[' . localtime(shift) . '] [' . shift() . '] ' . join("\n", @_, '') }; |
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
5
|
|
|
5
|
1
|
2498
|
my ($class, $conf_file, $watch) = (@_); |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
100
|
|
|
25
|
$conf_file ||= { |
34
|
|
|
|
|
|
|
'log4perl.rootLogger' => 'DEBUG, SCREEN', |
35
|
|
|
|
|
|
|
'log4perl.appender.SCREEN' => 'Log::Log4perl::Appender::Screen', |
36
|
|
|
|
|
|
|
'log4perl.appender.SCREEN.layout' => 'PatternLayout', |
37
|
|
|
|
|
|
|
'log4perl.appender.SCREEN.layout.ConversionPattern' => '[%d] [mojo] [%p] %m%n', |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
5
|
50
|
|
|
|
10
|
if ($watch) { |
41
|
0
|
|
|
|
|
0
|
Log::Log4perl::init_and_watch($conf_file, $watch); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
5
|
|
|
|
|
26
|
Log::Log4perl->init_once($conf_file); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
12854
|
my $self = $class->SUPER::new(); |
48
|
5
|
|
|
|
|
47
|
$self->on( message => \&_message ); |
49
|
5
|
|
|
|
|
59
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Hmm. Ah, a picture of my mommy. |
53
|
|
|
|
|
|
|
{ |
54
|
6
|
|
|
6
|
|
27
|
no strict 'refs'; |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
2962
|
|
55
|
|
|
|
|
|
|
for my $level ( |
56
|
|
|
|
|
|
|
qw/ trace |
57
|
|
|
|
|
|
|
debug |
58
|
|
|
|
|
|
|
info |
59
|
|
|
|
|
|
|
warn |
60
|
|
|
|
|
|
|
error |
61
|
|
|
|
|
|
|
fatal |
62
|
|
|
|
|
|
|
logwarn |
63
|
|
|
|
|
|
|
logdie |
64
|
|
|
|
|
|
|
error_warn |
65
|
|
|
|
|
|
|
error_die |
66
|
|
|
|
|
|
|
logcarp |
67
|
|
|
|
|
|
|
logcluck |
68
|
|
|
|
|
|
|
logcroak |
69
|
|
|
|
|
|
|
logconfess |
70
|
|
|
|
|
|
|
/ ) { |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
*{ __PACKAGE__ . "::$level" } = |
73
|
|
|
|
|
|
|
sub { |
74
|
15
|
|
|
15
|
|
15196
|
return shift->emit( message => $level => @_ ); |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _message { |
80
|
11
|
|
|
11
|
|
88
|
my ($self, $level, @message ) = @_; |
81
|
11
|
|
|
|
|
12
|
my $depth = 3; |
82
|
11
|
|
|
|
|
17
|
local $Log::Log4perl::caller_depth |
83
|
|
|
|
|
|
|
= $Log::Log4perl::caller_depth + $depth; |
84
|
|
|
|
|
|
|
|
85
|
11
|
100
|
|
|
|
17
|
if ($self->_get_logger( $depth )->$level( @message )) { |
86
|
10
|
|
|
|
|
1767
|
my $history = $self->history; |
87
|
10
|
|
|
|
|
39
|
my $max = $self->max_history_size; |
88
|
10
|
|
|
|
|
50
|
push @$history => [ time, $level, @message ]; |
89
|
10
|
100
|
|
|
|
22
|
splice (@$history, 0, scalar @$history - $max) |
90
|
|
|
|
|
|
|
if scalar @$history > $max; |
91
|
|
|
|
|
|
|
} |
92
|
11
|
|
|
|
|
40
|
return $self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
1
|
1
|
1619
|
sub log { shift->emit('message', lc(shift), @_) } |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
1
|
1
|
764
|
sub is_trace { shift->_get_logger->is_trace } |
98
|
3
|
|
|
3
|
1
|
818
|
sub is_debug { shift->_get_logger->is_debug } |
99
|
1
|
|
|
1
|
1
|
291
|
sub is_info { shift->_get_logger->is_info } |
100
|
1
|
|
|
1
|
1
|
286
|
sub is_warn { shift->_get_logger->is_warn } |
101
|
1
|
|
|
1
|
1
|
286
|
sub is_error { shift->_get_logger->is_error } |
102
|
1
|
|
|
1
|
1
|
292
|
sub is_fatal { shift->_get_logger->is_fatal } |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub is_level { |
105
|
12
|
|
|
12
|
1
|
3767
|
my ($self, $level) = (@_); |
106
|
12
|
50
|
|
|
|
26
|
return 0 unless $level; |
107
|
|
|
|
|
|
|
|
108
|
12
|
50
|
|
|
|
59
|
if ($level =~ m/^(?:trace|debug|info|warn|error|fatal)$/o) { |
109
|
12
|
|
|
|
|
19
|
my $is_level = "is_$level"; |
110
|
12
|
|
|
|
|
15
|
return $self->_get_logger->$is_level; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else { |
113
|
0
|
|
|
|
|
0
|
return 0; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub level { |
118
|
11
|
|
|
11
|
1
|
3612
|
my ($self, $level) = (@_); |
119
|
11
|
|
|
|
|
20
|
my $logger = $self->_get_logger; |
120
|
|
|
|
|
|
|
|
121
|
11
|
|
|
|
|
183
|
require Log::Log4perl::Level; |
122
|
11
|
100
|
|
|
|
17
|
if ($level) { |
123
|
9
|
|
|
|
|
40
|
return $logger->level( Log::Log4perl::Level::to_priority(uc $level) ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
2
|
|
|
|
|
5
|
return Log::Log4perl::Level::to_level( $logger->level() ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# $_[0] == $self, $_[1] == optional caller level (defaults to 1) |
131
|
|
|
|
|
|
|
sub _get_logger { |
132
|
42
|
|
100
|
42
|
|
254
|
return Log::Log4perl->get_logger( scalar caller( $_[1] || 1 ) ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
__END__ |