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