line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::AccessLog; |
2
|
6
|
|
|
6
|
|
23338
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
166
|
|
3
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
169
|
|
4
|
6
|
|
|
6
|
|
29
|
use parent qw( Plack::Middleware ); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
35
|
|
5
|
6
|
|
|
6
|
|
341
|
use Plack::Util::Accessor qw( logger format compiled_format char_handlers block_handlers ); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
64
|
|
6
|
6
|
|
|
6
|
|
2450
|
use Apache::LogFormat::Compiler; |
|
6
|
|
|
|
|
66862
|
|
|
6
|
|
|
|
|
2155
|
|
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
|
25
|
my $self = shift; |
15
|
16
|
|
100
|
|
|
46
|
my $fmt = $self->format || "combined"; |
16
|
16
|
100
|
|
|
|
48
|
$fmt = $formats{$fmt} if exists $formats{$fmt}; |
17
|
16
|
|
100
|
|
|
47
|
$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
|
|
|
|
|
20
|
my($env) = @_; |
26
|
|
|
|
|
|
|
|
27
|
11
|
|
|
|
|
81
|
my $res = $self->app->($env); |
28
|
|
|
|
|
|
|
|
29
|
11
|
50
|
33
|
|
|
95
|
if ( ref($res) && ref($res) eq 'ARRAY' ) { |
30
|
11
|
|
|
|
|
32
|
my $content_length = Plack::Util::content_length($res->[2]); |
31
|
11
|
|
|
|
|
53
|
my $log_line = $self->log_line($res->[0], $res->[1], $env, { content_length => $content_length }); |
32
|
11
|
50
|
|
|
|
3421
|
if ( my $logger = $self->logger ) { |
33
|
11
|
|
|
|
|
35
|
$logger->($log_line); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
0
|
$env->{'psgi.errors'}->print($log_line); |
37
|
|
|
|
|
|
|
} |
38
|
11
|
|
|
|
|
96
|
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
|
219
|
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
|
|
|
|
|
77
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |