line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::ParamLogger; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
10155
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
127
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
6
|
1
|
|
|
1
|
|
11
|
use Data::Dumper (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
347
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register |
11
|
|
|
|
|
|
|
{ |
12
|
7
|
|
|
7
|
1
|
28937
|
my ($self, $app, $options) = @_; |
13
|
7
|
100
|
100
|
|
|
22
|
return unless $app->mode eq 'development' or $options->{$app->mode}; |
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
|
|
69
|
my $level = $options->{level}; |
16
|
6
|
100
|
|
|
|
16
|
if(!$level) { |
17
|
|
|
|
|
|
|
# By default debug level is suppressed in production |
18
|
4
|
100
|
|
|
|
10
|
$level = $app->mode eq 'production' ? 'info' : 'debug'; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
6
|
100
|
|
|
|
34
|
croak "unknown log level '$level'" unless $app->log->can($level); |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
100
|
|
|
309
|
my $params = $options->{filter} || ['password']; |
24
|
5
|
100
|
|
|
|
14
|
$params = [ $params ] if ref $params ne 'ARRAY'; |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
9
|
my %filter; |
27
|
5
|
|
|
|
|
15
|
@filter{@$params} = (1) x @$params; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$app->hook(before_dispatch => sub { |
30
|
7
|
|
|
7
|
|
41440
|
my $c = shift; |
31
|
7
|
|
|
|
|
28
|
my $params = $c->req->params->to_hash; |
32
|
|
|
|
|
|
|
|
33
|
7
|
|
|
|
|
1029
|
for my $name (keys %$params) { |
34
|
7
|
50
|
|
|
|
23
|
next unless defined $params->{$name}; |
35
|
|
|
|
|
|
|
|
36
|
7
|
100
|
|
|
|
23
|
if($filter{$name}) { |
|
|
50
|
|
|
|
|
|
37
|
4
|
|
|
|
|
7
|
$params->{$name} = '#' x 8; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif(length($params->{$name}) > 75) { |
40
|
0
|
|
|
|
|
0
|
substr($params->{$name}, 75) = '...'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
21
|
my $path = $c->req->url->path; |
45
|
7
|
50
|
|
|
|
386
|
$path = "/$path" if index($path, '/') != 0; # Mojo doesn't always add the slash |
46
|
|
|
|
|
|
|
|
47
|
7
|
|
|
|
|
178
|
my $message = sprintf '%s %s%s', $c->req->method, $path, Data::Dumper->new([$params])->Terse(1)->Indent(0)->Useqq(1)->Pad(' ')->Dump; |
48
|
7
|
|
|
|
|
752
|
eval { $c->app->log->$level($message) }; |
|
7
|
|
|
|
|
16
|
|
49
|
7
|
50
|
|
|
|
987
|
if($@) { |
50
|
0
|
|
|
|
|
|
$c->render_exception($@); |
51
|
0
|
|
|
|
|
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
5
|
|
|
|
|
28
|
}); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |