| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Plack::Middleware::AccessLog; |
|
2
|
6
|
|
|
6
|
|
19932
|
use strict; |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
159
|
|
|
3
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
152
|
|
|
4
|
6
|
|
|
6
|
|
24
|
use parent qw( Plack::Middleware ); |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
32
|
|
|
5
|
6
|
|
|
6
|
|
314
|
use Plack::Util::Accessor qw( logger format compiled_format char_handlers block_handlers ); |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
34
|
|
|
6
|
6
|
|
|
6
|
|
2393
|
use Apache::LogFormat::Compiler; |
|
|
6
|
|
|
|
|
62028
|
|
|
|
6
|
|
|
|
|
2121
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my %formats = ( |
|
9
|
|
|
|
|
|
|
common => '%h %l %u %t "%r" %>s %b', |
|
10
|
|
|
|
|
|
|
combined => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"', |
|
11
|
|
|
|
|
|
|
); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub prepare_app { |
|
14
|
16
|
|
|
16
|
1
|
27
|
my $self = shift; |
|
15
|
16
|
|
100
|
|
|
52
|
my $fmt = $self->format || "combined"; |
|
16
|
16
|
100
|
|
|
|
117
|
$fmt = $formats{$fmt} if exists $formats{$fmt}; |
|
17
|
16
|
|
100
|
|
|
59
|
$self->compiled_format(Apache::LogFormat::Compiler->new($fmt, |
|
|
|
|
100
|
|
|
|
|
|
18
|
|
|
|
|
|
|
char_handlers => $self->char_handlers || {}, |
|
19
|
|
|
|
|
|
|
block_handlers => $self->block_handlers || {}, |
|
20
|
|
|
|
|
|
|
)); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub call { |
|
24
|
11
|
|
|
11
|
1
|
19
|
my $self = shift; |
|
25
|
11
|
|
|
|
|
24
|
my($env) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
11
|
|
|
|
|
58
|
my $res = $self->app->($env); |
|
28
|
|
|
|
|
|
|
|
|
29
|
11
|
50
|
33
|
|
|
98
|
if ( ref($res) && ref($res) eq 'ARRAY' ) { |
|
30
|
11
|
|
|
|
|
36
|
my $content_length = Plack::Util::content_length($res->[2]); |
|
31
|
11
|
|
|
|
|
49
|
my $log_line = $self->log_line($res->[0], $res->[1], $env, { content_length => $content_length }); |
|
32
|
11
|
50
|
|
|
|
3494
|
if ( my $logger = $self->logger ) { |
|
33
|
11
|
|
|
|
|
30
|
$logger->($log_line); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
else { |
|
36
|
0
|
|
|
|
|
0
|
$env->{'psgi.errors'}->print($log_line); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
11
|
|
|
|
|
94
|
return $res; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return $self->response_cb($res, sub { |
|
42
|
0
|
|
|
0
|
|
0
|
my $res = shift; |
|
43
|
0
|
|
|
|
|
0
|
my $content_length = Plack::Util::content_length($res->[2]); |
|
44
|
0
|
|
|
|
|
0
|
my $log_line = $self->log_line($res->[0], $res->[1], $env, { content_length => $content_length }); |
|
45
|
0
|
0
|
|
|
|
0
|
if ( my $logger = $self->logger ) { |
|
46
|
0
|
|
|
|
|
0
|
$logger->($log_line); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
else { |
|
49
|
0
|
|
|
|
|
0
|
$env->{'psgi.errors'}->print($log_line); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
0
|
|
|
|
|
0
|
}); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub log_line { |
|
55
|
23
|
|
|
23
|
0
|
232
|
my($self, $status, $headers, $env, $opts) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->compiled_format->log_line( |
|
58
|
|
|
|
|
|
|
$env, |
|
59
|
|
|
|
|
|
|
[$status,$headers], |
|
60
|
|
|
|
|
|
|
$opts->{content_length}, |
|
61
|
|
|
|
|
|
|
$opts->{time} |
|
62
|
23
|
|
|
|
|
80
|
); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |