| 1 | package Dancer::Logger::Log4perl; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | # | ||||||||||||||
| 4 | # ABSTRACT: Dancer adapter for Log::Log4perl | ||||||||||||||
| 5 | # | ||||||||||||||
| 6 | |||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use base 'Dancer::Logger::Abstract'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | ▶ | use Dancer::Config (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | ▶ | use Dancer::ModuleLoader (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 1 | our $VERSION = '0.9.0'; | |||||||||||||
| 16 | |||||||||||||||
| 17 | 1 | 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 | 0 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||
| 27 | 0 | my $self = shift; | |||||||||||||
| 28 | 0 | $self->SUPER::init(@_); | |||||||||||||
| 29 | |||||||||||||||
| 30 | 0 | my $conf = Dancer::Config::setting('log4perl'); | |||||||||||||
| 31 | 0 | ▶ | my $class = $conf->{tiny} ? 'Log::Log4perl::Tiny' : 'Log::Log4perl'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 0 | $self->{class} = $class; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | ▶ | unless ( Dancer::ModuleLoader->require($class) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 0 | carp "unable to load $class"; | |||||||||||||
| 36 | 0 | return; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | ▶ | if ( ! $conf->{no_init} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | 0 | ▶ | if ( $conf->{tiny} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | 0 | my $logger = $class->get_logger(); | |||||||||||||
| 42 | 0 | for my $accessor (qw( fh level layout format )) { | |||||||||||||
| 43 | 0 | ▶ | if ( exists $conf->{$accessor} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | $logger->$accessor($conf->{$accessor}); | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | } | ||||||||||||||
| 47 | } else { | ||||||||||||||
| 48 | my $l4p_conf = | ||||||||||||||
| 49 | exists $conf->{config_file} ? $conf->{config_file} | ||||||||||||||
| 50 | : exists $conf->{config} ? \$conf->{config} | ||||||||||||||
| 51 | 0 | ▶ | : \$default_config; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 52 | 0 | Log::Log4perl::init($l4p_conf); | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 0 | $self->{logger} = $class->get_logger(); | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 0 | ▶ | sub _log { | ||||||||||||
|
Subroutine
_log: not called CC=4 SCAR=30.0
| |||||||||||||||
| 60 | 0 | my ($self, $level, $message) = @_; | |||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | ▶ | $level = 'warn' if $level eq 'warning'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | 0 | ▶ | $level = 'trace' if $level eq 'core'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | ▶ | local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 3 if $self->{class} eq 'Log::Log4perl'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | |||||||||||||||
| 69 | 0 | $self->{logger}->$level($self->format_message($format_level => $message)); | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 1 | 1; | |||||||||||||
| 73 | __END__ | ||||||||||||||