line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
25
|
|
|
25
|
|
435
|
use 5.008001; |
|
25
|
|
|
|
|
84
|
|
2
|
25
|
|
|
25
|
|
131
|
use strict; |
|
25
|
|
|
|
|
51
|
|
|
25
|
|
|
|
|
735
|
|
3
|
25
|
|
|
25
|
|
155
|
use warnings; |
|
25
|
|
|
|
|
74
|
|
|
25
|
|
|
|
|
1281
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Log::Any::Proxy; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Log::Any generator proxy object |
8
|
|
|
|
|
|
|
our $VERSION = '1.716'; |
9
|
|
|
|
|
|
|
|
10
|
25
|
|
|
25
|
|
173
|
use Log::Any::Adapter::Util (); |
|
25
|
|
|
|
|
65
|
|
|
25
|
|
|
|
|
556
|
|
11
|
25
|
|
|
25
|
|
27701
|
use overload; |
|
25
|
|
|
|
|
23160
|
|
|
25
|
|
|
|
|
145
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _stringify_params { |
14
|
49
|
|
|
49
|
|
97
|
my @params = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
return map { |
17
|
49
|
100
|
|
|
|
95
|
!defined($_) |
|
33
|
100
|
|
|
|
252
|
|
|
|
100
|
|
|
|
|
|
18
|
|
|
|
|
|
|
? '' |
19
|
|
|
|
|
|
|
: ref($_) ? ( |
20
|
|
|
|
|
|
|
overload::OverloadedStringify($_) |
21
|
|
|
|
|
|
|
? "$_" |
22
|
|
|
|
|
|
|
: Log::Any::Adapter::Util::dump_one_line($_) |
23
|
|
|
|
|
|
|
) |
24
|
|
|
|
|
|
|
: $_ |
25
|
|
|
|
|
|
|
} @params; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _default_formatter { |
29
|
42
|
|
|
42
|
|
107
|
my ( $cat, $lvl, $format, @params ) = @_; |
30
|
42
|
100
|
|
|
|
133
|
return $format->() if ref($format) eq 'CODE'; |
31
|
|
|
|
|
|
|
|
32
|
41
|
|
|
|
|
93
|
my @new_params = _stringify_params(@params); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Perl 5.22 adds a 'redundant' warning if the number parameters exceeds |
35
|
|
|
|
|
|
|
# the number of sprintf placeholders. If a user does this, the warning |
36
|
|
|
|
|
|
|
# is issued from here, which isn't very helpful. Doing something |
37
|
|
|
|
|
|
|
# clever would be expensive, so instead we just disable warnings for |
38
|
|
|
|
|
|
|
# the final line of this subroutine. |
39
|
25
|
|
|
25
|
|
4362
|
no warnings; |
|
25
|
|
|
|
|
53
|
|
|
25
|
|
|
|
|
6314
|
|
40
|
41
|
|
|
|
|
467
|
return sprintf( $format, @new_params ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
65
|
|
|
65
|
0
|
138
|
my $class = shift; |
45
|
65
|
|
|
|
|
275
|
my $self = { formatter => \&_default_formatter, @_ }; |
46
|
65
|
50
|
|
|
|
269
|
unless ( $self->{adapter} ) { |
47
|
0
|
|
|
|
|
0
|
require Carp; |
48
|
0
|
|
|
|
|
0
|
Carp::croak("$class requires an 'adapter' parameter"); |
49
|
|
|
|
|
|
|
} |
50
|
65
|
50
|
|
|
|
171
|
unless ( defined $self->{category} ) { |
51
|
0
|
|
|
|
|
0
|
require Carp; |
52
|
0
|
|
|
|
|
0
|
Carp::croak("$class requires a 'category' parameter"); |
53
|
|
|
|
|
|
|
} |
54
|
65
|
50
|
|
|
|
143
|
unless ( $self->{context} ) { |
55
|
0
|
|
|
|
|
0
|
require Carp; |
56
|
0
|
|
|
|
|
0
|
Carp::croak("$class requires a 'context' parameter"); |
57
|
|
|
|
|
|
|
} |
58
|
65
|
|
|
|
|
114
|
bless $self, $class; |
59
|
65
|
|
|
|
|
224
|
$self->init(@_); |
60
|
65
|
|
|
|
|
216
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub clone { |
64
|
1
|
|
|
1
|
0
|
10
|
my $self = shift; |
65
|
1
|
|
|
|
|
3
|
return (ref $self)->new( %{ $self }, @_ ); |
|
1
|
|
|
|
|
5
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
65
|
0
|
|
sub init { } |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
for my $attr (qw/adapter category filter formatter prefix context/) { |
71
|
25
|
|
|
25
|
|
189
|
no strict 'refs'; |
|
25
|
|
|
|
|
56
|
|
|
25
|
|
|
|
|
3929
|
|
72
|
51
|
|
|
51
|
|
3018
|
*{$attr} = sub { return $_[0]->{$attr} }; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my %aliases = Log::Any::Adapter::Util::log_level_aliases(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Set up methods/aliases and detection methods/aliases |
78
|
|
|
|
|
|
|
foreach my $name ( Log::Any::Adapter::Util::logging_methods(), keys(%aliases) ) |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
my $realname = $aliases{$name} || $name; |
81
|
|
|
|
|
|
|
my $namef = $name . "f"; |
82
|
|
|
|
|
|
|
my $is_name = "is_$name"; |
83
|
|
|
|
|
|
|
my $is_realname = "is_$realname"; |
84
|
|
|
|
|
|
|
my $numeric = Log::Any::Adapter::Util::numeric_level($realname); |
85
|
25
|
|
|
25
|
|
181
|
no strict 'refs'; |
|
25
|
|
|
|
|
71
|
|
|
25
|
|
|
|
|
13329
|
|
86
|
|
|
|
|
|
|
*{$is_name} = sub { |
87
|
89
|
|
|
89
|
|
10492
|
my ($self) = @_; |
88
|
89
|
|
|
|
|
521
|
return $self->{adapter}->$is_realname; |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
*{$name} = sub { |
91
|
113
|
|
|
113
|
|
22494
|
my ( $self, @parts ) = @_; |
92
|
113
|
100
|
100
|
|
|
788
|
return if !$self->{adapter}->$is_realname && !defined wantarray; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $structured_logging = |
95
|
108
|
|
66
|
|
|
767
|
$self->{adapter}->can('structured') && !$self->{filter}; |
96
|
|
|
|
|
|
|
|
97
|
108
|
100
|
100
|
|
|
760
|
my $data_from_parts = pop @parts |
|
|
|
66
|
|
|
|
|
98
|
|
|
|
|
|
|
if ( @parts && ( ( ref $parts[-1] || '' ) eq ref {} ) ); |
99
|
108
|
|
|
|
|
357
|
my $data_from_context = $self->{context}; |
100
|
|
|
|
|
|
|
my $data = |
101
|
108
|
100
|
|
|
|
219
|
{ map {%$_} grep {$_ && %$_} $data_from_context, $data_from_parts }; |
|
23
|
|
|
|
|
90
|
|
|
216
|
|
|
|
|
723
|
|
102
|
|
|
|
|
|
|
|
103
|
108
|
100
|
|
|
|
333
|
if ($structured_logging) { |
104
|
15
|
50
|
|
|
|
38
|
unshift @parts, $self->{prefix} if $self->{prefix}; |
105
|
|
|
|
|
|
|
$self->{adapter} |
106
|
15
|
|
|
|
|
31
|
->structured( $realname, $self->{category}, @parts, grep {%$_} $data ); |
|
15
|
|
|
|
|
52
|
|
107
|
15
|
50
|
|
|
|
438
|
return unless defined wantarray; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
93
|
50
|
|
|
|
173
|
@parts = grep { defined($_) && length($_) } @parts; |
|
99
|
|
|
|
|
438
|
|
111
|
93
|
100
|
|
|
|
233
|
push @parts, _stringify_params($data) if %$data; |
112
|
|
|
|
|
|
|
|
113
|
93
|
|
|
|
|
580
|
my $message = join( " ", @parts ); |
114
|
93
|
100
|
66
|
|
|
344
|
if ( length $message && !$structured_logging ) { |
115
|
|
|
|
|
|
|
$message = |
116
|
|
|
|
|
|
|
$self->{filter}->( $self->{category}, $numeric, $message ) |
117
|
66
|
100
|
|
|
|
194
|
if defined $self->{filter}; |
118
|
66
|
50
|
33
|
|
|
305
|
if ( defined $message and length $message ) { |
119
|
|
|
|
|
|
|
$message = "$self->{prefix}$message" |
120
|
66
|
100
|
66
|
|
|
218
|
if defined $self->{prefix} && length $self->{prefix}; |
121
|
66
|
|
|
|
|
374
|
$self->{adapter}->$realname($message); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
93
|
100
|
|
|
|
488
|
return $message if defined wantarray; |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
*{$namef} = sub { |
127
|
46
|
|
|
46
|
|
342
|
my ( $self, @args ) = @_; |
128
|
46
|
50
|
66
|
|
|
209
|
return if !$self->{adapter}->$is_realname && !defined wantarray; |
129
|
|
|
|
|
|
|
my $message = |
130
|
46
|
|
|
|
|
142
|
$self->{formatter}->( $self->{category}, $numeric, @args ); |
131
|
46
|
100
|
66
|
|
|
258
|
return unless defined $message and length $message; |
132
|
19
|
|
|
|
|
90
|
return $self->$name($message); |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# vim: ts=4 sts=4 sw=4 et tw=75: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |