File Coverage

blib/lib/Mojolicious/Plugin/StaticLog.pm
Criterion Covered Total %
statement 15 15 100.0
branch 3 4 75.0
condition 2 2 100.0
subroutine 3 3 100.0
pod 1 1 100.0
total 24 25 96.0


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::StaticLog;
2 3     3   2210 use Mojo::Base 'Mojolicious::Plugin';
  3         8  
  3         26  
3              
4             our $VERSION = '0.07';
5              
6             sub register {
7 3     3 1 136 my ($self, $app, $conf) = @_;
8 3   100     24 my $level = $conf->{level} || 'debug';
9 3 50       21 die "$level: unsupported log-level"
10             unless $level =~ /^(debug|info|warn|error|fatal)$/;
11             $app->hook(
12             after_static => sub {
13 5     5   74261 my $c = shift;
14 5         19 my $log = $c->app->log;
15 5 100       53 return unless $log->is_level($level);
16 2         38 my $path = $c->req->url->path;
17 2         45 my $size = sprintf '%6s', $c->res->content->body_size;
18 2         97 my $code = $c->res->code;
19 2         44 $log->$level("Static $code $size $path");
20 3         39 });
21 3         76 return;
22             }
23              
24             1;
25             __END__