Dancer::Logger::File::PerRequest - per-request file-based logging engine for Dancer
## in yml config logger: "File::PerRequest"
Dancer::Logger::File::PerRequest is a per-request file-based logging engine for Dancer.
By default, it will be generating YYYYMMDDHHMMSS-$pid-$request_id.log under logs of application dir.
the stuff can be configured as
per pid
set 'logfile_callback' => sub { return $$ . '.log'; };
will genereate $pid.log
per hour
set 'logfile_callback' => sub { my @d = localtime(); my $file = sprintf('%04d%02d%02d%02d', $d[5] + 1900, $d[4] + 1, $d[3], $d[2]); return $file . '.log'; };
will do file as YYYYMMDDHH.log
it's quite flexible that you can configure it as daily or daily + pid + server or whatever.
the log path, same as Dancer::Logger::File, default to $appdir/logs
hook 'before_file_per_request_close' => sub { my ($fh, $logfile) = @_; print $fh "# END on " . scalar(localtime()) . "\n"; };
hook 'after_file_per_request_close' => sub { my ($logfile, $response) = @_; # response as Dancer::Response if ($response->status >= 500) { ## server error # move file to error dir } else { # just rm it? unlink($logfile); } };
Fayland Lam <fayland@gmail.com>
Copyright 2014- Fayland Lam
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Dancer::Logger::File::PerRequest, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Logger::File::PerRequest
CPAN shell
perl -MCPAN -e shell install Dancer::Logger::File::PerRequest
For more information on module installation, please visit the detailed CPAN module installation guide.