line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2017 Koha-Suomi |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This file is part of Pootle-Client. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Pootle::Logger; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Modern::Perl '2015'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
125
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
binmode STDOUT, ':encoding(UTF-8)'; |
10
|
|
|
|
|
|
|
binmode STDERR, ':encoding(UTF-8)'; |
11
|
1
|
|
|
1
|
|
38
|
use feature 'signatures'; no warnings "experimental::signatures"; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
27
|
|
12
|
1
|
|
|
1
|
|
5
|
use Carp::Always; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
13
|
1
|
|
|
1
|
|
3
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
14
|
1
|
|
|
1
|
|
4
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
15
|
1
|
|
|
1
|
|
4
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
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
|
|
|
1
|
|
515
|
use Log::Log4perl; |
|
1
|
|
|
|
|
31687
|
|
|
1
|
|
|
|
|
5
|
|
37
|
|
|
|
|
|
|
our @ISA = qw(Log::Log4perl); |
38
|
|
|
|
|
|
|
Log::Log4perl->wrapper_register(__PACKAGE__); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $environmentAdjustmentDone; #Adjust all appenders only once |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub AUTOLOAD { |
43
|
0
|
|
|
0
|
|
|
my $l = shift(@_); |
44
|
0
|
|
|
|
|
|
my $method = our $AUTOLOAD; |
45
|
0
|
|
|
|
|
|
$method =~ s/.*://; |
46
|
0
|
0
|
|
|
|
|
unless (blessed($l)) { |
47
|
0
|
|
|
|
|
|
die __PACKAGE__." invoked with an unblessed reference??"; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
0
|
|
|
|
|
unless ($l->{_log}) { |
50
|
0
|
|
|
|
|
|
$l->{_log} = get_logger($l); |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
return $l->{_log}->$method(@_); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_logger { |
56
|
0
|
0
|
|
0
|
0
|
|
initLogger() unless Log::Log4perl->initialized(); |
57
|
0
|
|
|
|
|
|
my $l = Log::Log4perl->get_logger(); |
58
|
0
|
|
|
|
|
|
return $l; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub initLogger { |
62
|
|
|
|
|
|
|
Log::Log4perl->easy_init({ |
63
|
0
|
|
0
|
0
|
0
|
|
level => _levelToLog4perlLevelInt($ENV{POOTLE_CLIENT_VERBOSITY} || 'WARN'), |
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, 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
|
|
|
0
|
|
|
sub _levelToLog4perlLevelInt($level) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
return 0 if $level =~ /ALL/i; |
83
|
0
|
0
|
|
|
|
|
return 5000 if $level =~ /TRACE/i; |
84
|
0
|
0
|
|
|
|
|
return 10000 if $level =~ /DEBUG/i; |
85
|
0
|
0
|
|
|
|
|
return 20000 if $level =~ /INFO/i; |
86
|
0
|
0
|
|
|
|
|
return 30000 if $level =~ /WARN/i; |
87
|
0
|
0
|
|
|
|
|
return 40000 if $level =~ /ERROR/i; |
88
|
0
|
0
|
|
|
|
|
return 50000 if $level =~ /FATAL/i; |
89
|
0
|
0
|
|
|
|
|
return (2 ** 31) - 1 if $level =~ /OFF/i; #presumably INT MAX |
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
|
|
|
|
|
|
|
sub flatten { |
105
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
106
|
0
|
0
|
0
|
|
|
|
die __PACKAGE__."->flatten() invoked improperly. Invoke it with \$logger->flatten(\@params)" unless ((blessed($self) && $self->isa(__PACKAGE__)) || ($self eq __PACKAGE__)); |
|
|
|
0
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return Data::Dumper->new([@_],[])->Terse(1)->Indent(1)->Varname('')->Maxdepth(0)->Sortkeys(1)->Quotekeys(1)->Dump(); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |