line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::AccessLog; |
2
|
6
|
|
|
6
|
|
26107
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
199
|
|
3
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
173
|
|
4
|
6
|
|
|
6
|
|
31
|
use parent qw( Plack::Middleware ); |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
51
|
|
5
|
6
|
|
|
6
|
|
347
|
use Plack::Util::Accessor qw( logger format compiled_format char_handlers block_handlers ); |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
40
|
|
6
|
6
|
|
|
6
|
|
3497
|
use Apache::LogFormat::Compiler; |
|
6
|
|
|
|
|
76222
|
|
|
6
|
|
|
|
|
2468
|
|
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
|
32
|
my $self = shift; |
15
|
16
|
|
100
|
|
|
60
|
my $fmt = $self->format || "combined"; |
16
|
16
|
100
|
|
|
|
69
|
$fmt = $formats{$fmt} if exists $formats{$fmt}; |
17
|
16
|
|
100
|
|
|
60
|
$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
|
27
|
my $self = shift; |
25
|
11
|
|
|
|
|
22
|
my($env) = @_; |
26
|
|
|
|
|
|
|
|
27
|
11
|
|
|
|
|
60
|
my $res = $self->app->($env); |
28
|
|
|
|
|
|
|
|
29
|
11
|
50
|
33
|
|
|
109
|
if ( ref($res) && ref($res) eq 'ARRAY' ) { |
30
|
11
|
|
|
|
|
57
|
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
|
|
|
|
3896
|
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
|
|
|
|
|
99
|
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
|
265
|
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
|
|
|
|
|
75
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |