line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
5
|
|
|
5
|
|
242211
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
292
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Plack::Middleware::Debug::Log4perl; |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
1723
|
use parent qw(Plack::Middleware::Debug::Base); |
|
5
|
|
|
|
|
707
|
|
|
5
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
193631
|
use Log::Log4perl qw(get_logger :levels); |
|
5
|
|
|
|
|
340544
|
|
|
5
|
|
|
|
|
39
|
|
11
|
5
|
|
|
5
|
|
570
|
use Log::Log4perl::Layout; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
100
|
|
12
|
5
|
|
|
5
|
|
26
|
use Log::Log4perl::Level; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
25
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
6456
|
use Data::Dumper; |
|
5
|
|
|
|
|
47407
|
|
|
5
|
|
|
|
|
2417
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# let's try keeping a handle on the layout |
17
|
|
|
|
|
|
|
my $timer; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub run |
20
|
|
|
|
|
|
|
{ |
21
|
8
|
|
|
8
|
1
|
1230120
|
my($self, $env, $panel) = @_; |
22
|
|
|
|
|
|
|
|
23
|
8
|
100
|
|
|
|
304
|
if (Log::Log4perl->initialized()) { |
24
|
|
|
|
|
|
|
|
25
|
7
|
100
|
|
|
|
191
|
if (my $appender = Log::Log4perl->appender_by_name('psgi_debug_panel')) { |
26
|
|
|
|
|
|
|
|
27
|
6
|
|
|
|
|
230
|
$appender->clear(); |
28
|
|
|
|
|
|
|
|
29
|
6
|
100
|
|
|
|
158
|
$timer->reset() if $timer; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
59
|
my $logger = Log::Log4perl->get_logger(""); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Define a layout |
36
|
1
|
|
|
|
|
108
|
my $layout = Log::Log4perl::Layout::PatternLayout->new("%r >> %p >> %m >> %c >> at %F line %L%n"); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Define an 'in memory' appender |
39
|
1
|
|
|
|
|
598
|
my $appender = Log::Log4perl::Appender->new( |
40
|
|
|
|
|
|
|
"Log::Log4perl::Appender::TestBuffer", |
41
|
|
|
|
|
|
|
name => "psgi_debug_panel"); |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
3457
|
$appender->layout($layout); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
22
|
$logger->add_appender($appender); |
46
|
1
|
|
|
|
|
1331
|
$logger->level($TRACE); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# hang on to the timer, so we can reset it |
49
|
1
|
|
|
|
|
950
|
$timer = $layout->{timer}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return sub { |
54
|
8
|
|
|
8
|
|
258956
|
my $res = shift; |
55
|
|
|
|
|
|
|
|
56
|
8
|
50
|
|
|
|
70
|
if (my $appender = Log::Log4perl->appenders()->{psgi_debug_panel}) { |
57
|
|
|
|
|
|
|
|
58
|
8
|
|
|
|
|
94
|
my $log = $appender->{appender}->{buffer}; |
59
|
|
|
|
|
|
|
|
60
|
8
|
|
|
|
|
290
|
$log =~ s/ >> /\n/g; |
61
|
8
|
|
|
|
|
287
|
my $list = [ split '\n', $log ]; |
62
|
|
|
|
|
|
|
|
63
|
8
|
|
|
|
|
139
|
$panel->content( sub { $self->render_list_pairs($list) } ); |
|
8
|
|
|
|
|
205143
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
$panel->content( 'Log4perl appender not enabled' ); |
68
|
|
|
|
|
|
|
} |
69
|
8
|
|
|
|
|
302
|
}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $list_template = __PACKAGE__->build_template(<<'EOTMPL'); |
73
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
| Time |
77
|
|
|
|
|
|
|
| Level |
78
|
|
|
|
|
|
|
| Message |
79
|
|
|
|
|
|
|
| Source |
80
|
|
|
|
|
|
|
| Line |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
| |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
% my $i; |
85
|
|
|
|
|
|
|
% while (@{$_[0]->{list}}) { |
86
|
|
|
|
|
|
|
% my($time, $level, $message, $source, $line) = splice(@{$_[0]->{list}}, 0, 5); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
| <%= $time %> |
89
|
|
|
|
|
|
|
| <%= $level %> |
90
|
|
|
|
|
|
|
| <%= $message %> |
91
|
|
|
|
|
|
|
| <%= $source %> |
92
|
|
|
|
|
|
|
| <%= $line %> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
% } |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
| |
97
|
|
|
|
|
|
|
EOTMPL |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub render_list_pairs { |
100
|
|
|
|
|
|
|
|
101
|
8
|
|
|
8
|
0
|
81
|
my ($self, $list, $sections) = @_; |
102
|
8
|
50
|
|
|
|
54
|
if ($sections) { |
103
|
0
|
|
|
|
|
0
|
$self->render($list_template, { list => $list }); |
104
|
|
|
|
|
|
|
}else{ |
105
|
8
|
|
|
|
|
127
|
$self->render($list_template, { list => $list }); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |