line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Log::Minimal; |
2
|
4
|
|
|
4
|
|
325639
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
164
|
|
3
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
149
|
|
4
|
4
|
|
|
4
|
|
3793
|
use parent qw(Plack::Middleware); |
|
4
|
|
|
|
|
386
|
|
|
4
|
|
|
|
|
35
|
|
5
|
4
|
|
|
4
|
|
547907
|
use Plack::Util::Accessor qw( autodump loglevel formatter encoding); |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
40
|
|
6
|
4
|
|
|
4
|
|
183677
|
use Log::Minimal 0.09; |
|
4
|
|
|
|
|
49460
|
|
|
4
|
|
|
|
|
38
|
|
7
|
4
|
|
|
4
|
|
607
|
use Carp qw/croak/; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
271
|
|
8
|
4
|
|
|
4
|
|
34282
|
use Encode; |
|
4
|
|
|
|
|
40482
|
|
|
4
|
|
|
|
|
2140
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub build_logger { |
13
|
4
|
|
|
4
|
0
|
12
|
my ($self, $env) = @_; |
14
|
|
|
|
|
|
|
return sub { |
15
|
12
|
|
|
12
|
|
27456
|
my ( $time, $type, $message, $trace, $raw_message) = @_; |
16
|
12
|
100
|
|
|
|
159
|
$message = Encode::encode($self->encoding,$message) if Encode::is_utf8($message); |
17
|
12
|
|
|
|
|
4988
|
$env->{'psgi.errors'}->print($self->formatter->($env, $time, $type, $message, $trace, $raw_message)); |
18
|
4
|
|
|
|
|
33
|
}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub prepare_app { |
23
|
4
|
|
|
4
|
1
|
1328
|
my $self = shift; |
24
|
|
|
|
|
|
|
$self->formatter(sub{ |
25
|
8
|
|
|
8
|
|
57
|
my ($env, $time, $type, $message, $trace, $raw_message) = @_; |
26
|
8
|
|
|
|
|
79
|
sprintf "%s [%s] [%s] %s at %s\n", $time, $type, $env->{REQUEST_URI}, $message, $trace; |
27
|
4
|
100
|
|
|
|
20
|
}) unless $self->formatter; |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
100
|
|
|
445
|
my $encoding = find_encoding($self->encoding || 'utf8'); |
30
|
4
|
100
|
|
|
|
41356
|
croak(sprintf 'encoding %s no found', $self->encoding) unless ref $encoding; |
31
|
3
|
|
|
|
|
22
|
$self->encoding($encoding); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub call { |
35
|
4
|
|
|
4
|
1
|
362010
|
my ($self, $env) = @_; |
36
|
4
|
|
|
|
|
20
|
local $Log::Minimal::PRINT = $self->build_logger($env); |
37
|
4
|
100
|
66
|
|
|
95
|
local $ENV{$Log::Minimal::ENV_DEBUG} = ($ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development') ? 1 : 0; |
38
|
4
|
50
|
|
|
|
30
|
local $Log::Minimal::AUTODUMP = 1 if $self->autodump; |
39
|
4
|
100
|
66
|
|
|
372
|
local $Log::Minimal::COLOR = 1 if $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development'; |
40
|
4
|
100
|
|
|
|
19
|
local $Log::Minimal::LOG_LEVEL = $self->loglevel if $self->loglevel; |
41
|
4
|
|
|
|
|
65
|
$self->app->($env); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
__END__ |