line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Logger::Log4perl; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# ABSTRACT: Dancer adapter for Log::Log4perl |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
25249
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
9
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
99
|
|
10
|
1
|
|
|
1
|
|
6
|
use base 'Dancer::Logger::Abstract'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1011
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
265057
|
use Dancer::Config (); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
16
|
|
13
|
1
|
|
|
1
|
|
5
|
use Dancer::ModuleLoader (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
389
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.9.0'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $default_config = <<'END_OF_CONFIG'; |
18
|
|
|
|
|
|
|
log4perl.logger = ALL, Screen |
19
|
|
|
|
|
|
|
log4perl.appender.Screen = Log::Log4perl::Appender::Screen |
20
|
|
|
|
|
|
|
log4perl.appender.Screen.stderr = 1 |
21
|
|
|
|
|
|
|
log4perl.appender.Screen.stdout = 0 |
22
|
|
|
|
|
|
|
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout |
23
|
|
|
|
|
|
|
log4perl.appender.Screen.layout.ConversionPattern = [%d] [%-5p] %m%n |
24
|
|
|
|
|
|
|
END_OF_CONFIG |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub init { |
27
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
28
|
0
|
|
|
|
|
|
$self->SUPER::init(@_); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $conf = Dancer::Config::setting('log4perl'); |
31
|
0
|
0
|
|
|
|
|
my $class = $conf->{tiny} ? 'Log::Log4perl::Tiny' : 'Log::Log4perl'; |
32
|
0
|
|
|
|
|
|
$self->{class} = $class; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
unless ( Dancer::ModuleLoader->require($class) ) { |
35
|
0
|
|
|
|
|
|
carp "unable to load $class"; |
36
|
0
|
|
|
|
|
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ( ! $conf->{no_init} ) { |
40
|
0
|
0
|
|
|
|
|
if ( $conf->{tiny} ) { |
41
|
0
|
|
|
|
|
|
my $logger = $class->get_logger(); |
42
|
0
|
|
|
|
|
|
for my $accessor (qw( fh level layout format )) { |
43
|
0
|
0
|
|
|
|
|
if ( exists $conf->{$accessor} ) { |
44
|
0
|
|
|
|
|
|
$logger->$accessor($conf->{$accessor}); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
0
|
|
|
|
|
my $l4p_conf = |
|
|
0
|
|
|
|
|
|
49
|
|
|
|
|
|
|
exists $conf->{config_file} ? $conf->{config_file} |
50
|
|
|
|
|
|
|
: exists $conf->{config} ? \$conf->{config} |
51
|
|
|
|
|
|
|
: \$default_config; |
52
|
0
|
|
|
|
|
|
Log::Log4perl::init($l4p_conf); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->{logger} = $class->get_logger(); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _log { |
60
|
0
|
|
|
0
|
|
|
my ($self, $level, $message) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
$level = 'warn' if $level eq 'warning'; |
63
|
0
|
0
|
|
|
|
|
$level = 'trace' if $level eq 'core'; |
64
|
0
|
|
|
|
|
|
my $format_level = $level; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Adjust the caller level since we've introduced additional levels. Does not apply to Tiny module. |
67
|
0
|
0
|
|
|
|
|
local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 3 if $self->{class} eq 'Log::Log4perl'; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->{logger}->$level($self->format_message($format_level => $message)); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
__END__ |