line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Plugin::Encode; |
2
|
|
|
|
|
|
|
# ABSTRACT: Output message encoding for log adapters |
3
|
|
|
|
|
|
|
$Log::Any::Plugin::Encode::VERSION = '0.011'; |
4
|
3
|
|
|
3
|
|
2123
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
79
|
|
5
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
80
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
14
|
use Carp qw( croak ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
172
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
625
|
use Encode qw( find_encoding ); |
|
3
|
|
|
|
|
8720
|
|
|
3
|
|
|
|
|
150
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
17
|
use Log::Any::Plugin::Util qw( get_old_method set_new_method ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
637
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub install { |
15
|
3
|
|
|
3
|
1
|
9
|
my ($class, $adapter_class, %args) = @_; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
100
|
|
|
14
|
my $encoding = $args{encoding} || 'utf8'; |
18
|
3
|
50
|
|
|
|
10
|
my $encoder = find_encoding($encoding) or |
19
|
|
|
|
|
|
|
croak "Could not find encoder for encoding[$encoding], check encoding value for typos, or codec installed"; |
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
69
|
for my $method_name ( Log::Any->logging_methods() ) { |
22
|
27
|
|
|
|
|
62
|
my $old_method = get_old_method($adapter_class, $method_name); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
set_new_method($adapter_class, $method_name, sub { |
25
|
3
|
|
|
3
|
|
1854
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
10
|
my @encoded_msgs = map { $encoder->encode($_, Encode::FB_WARN) } @_; |
|
3
|
|
|
|
|
24
|
|
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
11
|
return $self->$old_method(@encoded_msgs); |
30
|
27
|
|
|
|
|
96
|
}); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |