| 1 | # Copyright (C) 2017 Koha-Suomi | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of Pootle-Client. | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package Pootle::Logger; | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Modern::Perl '2015'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | binmode STDOUT, ':encoding(UTF-8)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | binmode STDERR, ':encoding(UTF-8)'; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use feature 'signatures'; no warnings "experimental::signatures"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp::Always; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | =head2 Pootle::Logger | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | Wrapper for the awesome Log::Log4perl | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =head2 Synopsis | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $ENV{POOTLE_CLIENT_VERBOSITY} = 'DEBUG'; #Set the log verbosity using Log::Log4perl log levels | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | use Pootle::Logger; | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $l = bless({}, 'Pootle::Logger'); #Lazy load package logger this way to avoid circular dependency issues with logger includes from many packages | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | sub faraway { | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | $l->debug("Debugging params: "$l->flatten(@_)) if $l->is_debug(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | $l->isa('Log::Log4perl') logger. Have fun! | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use Log::Log4perl; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | our @ISA = qw(Log::Log4perl); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | Log::Log4perl->wrapper_register(__PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $environmentAdjustmentDone; #Adjust all appenders only once | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $l = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $method = our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $method =~ s/.*://; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | unless (blessed($l)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | die __PACKAGE__." invoked with an unblessed reference??"; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | unless ($l->{_log}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $l->{_log} = get_logger($l); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $l->{_log}->$method(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub get_logger { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_logger: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | initLogger() unless Log::Log4perl->initialized(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $l = Log::Log4perl->get_logger(); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return $l; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub initLogger { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initLogger: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | Log::Log4perl->easy_init({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | level => _levelToLog4perlLevelInt($ENV{POOTLE_CLIENT_VERBOSITY} || 'WARN'), | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{'POOTLE_CLIENT_VERBOSITY'} || 'WARN'
MC/DC0%0/1
$ENV{'POOTLE_CLIENT_VERBOSITY'} || 'WARN'
$ENV{'POOTLE_CLIENT_VERBOSITY'}
Truth table0%0/2
A
A= $ENV{'POOTLE_CLIENT_VERBOSITY'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | utf8 => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | layout => '[%d{HH:mm:ss}] %p %M(): %m%n', | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | =head2 _levelToLog4perlLevelInt | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | There is a bug in Log4perl, where loading | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | use Log::Log4perl qw(:easy); | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | to namespace in this file causes | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | Deep recursion on subroutine "Log::Log4perl::get_logger" at /usr/share/perl5/Log/Log4perl.pm line 339, <FH> line 92. | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | Work around by not importing log levels, and manually duplicating them here. | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | see /usr/share/perl5/Log/Log4perl/Level.pm for level integers | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _levelToLog4perlLevelInt($level) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_levelToLog4perlLevelInt: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return 0 if $level =~ /ALL/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return 5000 if $level =~ /TRACE/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return 10000 if $level =~ /DEBUG/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return 20000 if $level =~ /INFO/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return 30000 if $level =~ /WARN/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | return 40000 if $level =~ /ERROR/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return 50000 if $level =~ /FATAL/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return (2 ** 31) - 1 if $level =~ /OFF/i; #presumably INT MAX | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | die "_levelToLog4perlLevelInt():> Unknown log level POOTLE_CLIENT_VERBOSITY=$level"; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | =head2 flatten | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | my $string = $logger->flatten(@_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | Given a bunch of $@%, the subroutine flattens those objects to a single human-readable string. | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | @PARAMS Anything, concatenates parameters to one flat string | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | @RETURNS String, params flattened | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub flatten { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flatten: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | die __PACKAGE__."->flatten() invoked improperly. Invoke it with \$logger->flatten(\@params)" unless ((blessed($self) && $self->isa(__PACKAGE__)) || ($self eq __PACKAGE__)); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
builtin::blessed($self) and $self->isa(__PACKAGE__) or $self eq __PACKAGE__
builtin::blessed($self) and $self->isa(__PACKAGE__)
MC/DC0%0/3
builtin::blessed($self) and $self->isa(__PACKAGE__) or $self eq __PACKAGE__
builtin::blessed($self)
$self->isa(__PACKAGE__)
$self eq __PACKAGE__
Truth table0%0/5
A and B or C
A= builtin::blessed($self)B= $self->isa(__PACKAGE__)C= $self eq __PACKAGE__
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return Data::Dumper->new([@_],[])->Terse(1)->Indent(1)->Varname('')->Maxdepth(0)->Sortkeys(1)->Quotekeys(1)->Dump(); | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||