line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Log4perl::DataDumper; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27557
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
211386
|
use Data::Dumper; |
|
1
|
|
|
|
|
14766
|
|
|
1
|
|
|
|
|
478
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub override |
11
|
|
|
|
|
|
|
{ |
12
|
2
|
|
|
2
|
0
|
5108
|
my ($log, $multiline) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
|
|
6
|
my $oldcoderef = $log->{OFF}; # OFF is always "ON" |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $overridesub = sub |
17
|
|
|
|
|
|
|
{ |
18
|
2
|
|
|
2
|
|
22
|
my $logger = shift; |
19
|
2
|
|
|
|
|
4
|
my $level = pop; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Reasonably nice options: |
23
|
|
|
|
|
|
|
# Should I allow user to change these? |
24
|
|
|
|
|
|
|
# |
25
|
2
|
|
|
|
|
3
|
local $Data::Dumper::Indent = 1; |
26
|
2
|
|
|
|
|
4
|
local $Data::Dumper::Quotekeys = 0; |
27
|
2
|
|
|
|
|
3
|
local $Data::Dumper::Terse = 1; |
28
|
2
|
|
|
|
|
3
|
local $Data::Dumper::Sortkeys = 1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# Go ahead and handle CODE and filter before calling oldcoderef |
32
|
|
|
|
|
|
|
# so they are coverred by multiline |
33
|
|
|
|
|
|
|
# |
34
|
2
|
50
|
33
|
|
|
6
|
@_ = map { ref $_ |
|
4
|
50
|
|
|
|
35
|
|
|
|
100
|
|
|
|
|
|
35
|
|
|
|
|
|
|
? (ref $_ eq 'CODE' |
36
|
|
|
|
|
|
|
? $_->() |
37
|
|
|
|
|
|
|
: ((ref $_ eq 'HASH' and ref $_->{filter} eq 'CODE') |
38
|
|
|
|
|
|
|
? $_->{filter}->($_->{value}) |
39
|
|
|
|
|
|
|
: Dumper($_))) |
40
|
|
|
|
|
|
|
: $_ |
41
|
|
|
|
|
|
|
} @_; |
42
|
|
|
|
|
|
|
|
43
|
2
|
100
|
|
|
|
169
|
if ($multiline) |
44
|
|
|
|
|
|
|
{ |
45
|
1
|
|
|
|
|
4
|
foreach (@_) |
46
|
|
|
|
|
|
|
{ |
47
|
2
|
|
|
|
|
161
|
foreach my $line (split(/\r?\n/)) |
48
|
|
|
|
|
|
|
{ |
49
|
4
|
|
|
|
|
280
|
$oldcoderef->($logger, $line, $level); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else |
54
|
|
|
|
|
|
|
{ |
55
|
1
|
|
|
|
|
6
|
$oldcoderef->($logger, @_, $level); |
56
|
|
|
|
|
|
|
} |
57
|
2
|
|
|
|
|
12
|
}; |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
10
|
foreach my $levelname (keys %Log::Log4perl::Level::PRIORITY) |
60
|
|
|
|
|
|
|
{ |
61
|
16
|
100
|
|
|
|
42
|
if ($log->{$levelname} == $oldcoderef) |
62
|
|
|
|
|
|
|
{ |
63
|
10
|
|
|
|
|
19
|
$log->{$levelname} = $overridesub; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Log::Log4perl::DataDumper - Wrapper for Log4perl auto Data::Dumper objects |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SYNOPSIS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
use Log::Log4perl qw(get_logger); |
77
|
|
|
|
|
|
|
use Log::Log4perl::DataDumper; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $logger = get_logger(); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Log::Log4perl::DataDumper::override($logger); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$logger->debug('Some Object: ', ['an', 'array'], |
84
|
|
|
|
|
|
|
'Another: ', { a => 'b' }); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 DESCRIPTION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
The Log4perl FAQ has the question "How can I drill down on references |
89
|
|
|
|
|
|
|
before logging them?" |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
As discussed there, you don't want to say |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$logger->debug(Data::Dumper::Dumper($objref)) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
since the Dumper() will get called regardless of whether debugging is |
96
|
|
|
|
|
|
|
on or not. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This can be handled optimally a couple ways with the stock Log4perl |
99
|
|
|
|
|
|
|
mechanisms: |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$logger->debug(sub { Data::Dumper::Dumper($objref) }); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
or |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$logger->debug( {filter => \&Data::Dumper::Dumper, |
106
|
|
|
|
|
|
|
value => $objref} ); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
both of which are sort of ugly. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
After calling C, you can |
111
|
|
|
|
|
|
|
just say: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$logger->debug($objref); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
As a special added bonus, you can add an extra flag to the override line: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Log::Log4perl::DataDumper::override($logger, 1) |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
and it will automatically handle multiline messages in the style of |
120
|
|
|
|
|
|
|
L, but it will work |
121
|
|
|
|
|
|
|
with any Layout defined instead of just PatternLayout since they are |
122
|
|
|
|
|
|
|
handled "up front" so to speak. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SEE ALSO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
L |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Curt Tilmes, Ectilmes@cpan.orgE |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright (C) 2008 by Curt Tilmes |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
138
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
139
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |