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   2051 use Mojo::Base 'Mojolicious::Plugin';
  3         9  
  3         21  
3              
4             our $VERSION = '0.05';
5              
6             sub register {
7 3     3 1 142 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   72993 my $c = shift;
14 5         19 my $log = $c->app->log;
15 5 100       46 return unless $log->is_level($level);
16 2         25 my $path = $c->req->url->path;
17 2         45 my $size = sprintf '%6s', $c->res->content->body_size;
18 2         95 my $code = $c->res->code;
19 2         34 $log->$level("Static $code $size $path");
20 3         35 });
21 3         72 return;
22             }
23              
24             1;
25             __END__