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   2080 use Mojo::Base 'Mojolicious::Plugin';
  3         9  
  3         24  
3              
4             our $VERSION = '0.04';
5              
6             sub register {
7 3     3 1 129 my ($self, $app, $conf) = @_;
8 3   100     20 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   72671 my $c = shift;
14 5         16 my $log = $c->app->log;
15 5 100       52 return unless $log->is_level($level);
16 2         30 my $path = $c->req->url->path;
17 2         50 my $size = sprintf '%6s', $c->res->content->body_size;
18 2         98 my $code = $c->res->code;
19 2         38 $log->$level("Static $code $size $path");
20 3         33 });
21 3         66 return;
22             }
23              
24             1;
25             __END__