Plack::Middleware::PeriAHS::LogAccess - Log request
This document describes version 0.620 of Plack::Middleware::PeriAHS::LogAccess (from Perl distribution Perinci-Access-HTTP-Server), released on 2017-12-09.
# In app.psgi use Plack::Builder; builder { enable "PeriAHS::LogAccess", dest => "/path/to/api-access.log"; }
This middleware forwards the request to given app and logs request. Only requests which have executed action (has $env->{'periahs.start_action_time'} set) will be logged.
The log looks like this (all in one line):
[20/Aug/2011:22:05:38 +0000] [127.0.0.1] [tcp:80] [libby] call /MyModule/my_func [args 14 {"name":"val"}] [resp 12 [200,"OK",1]] 2.123ms 5.947ms
The second last field ("2.123ms") is time spent executing the Riap action (in this case, calling the subroutine), and the last field ("5.947ms") is time spent for the whole HTTP request (from client connect until HTTP response is sent).
This middleware should be put outermost (first) to be able to record request starting time more accurately.
dest => STR or OBJ
Either a string (path to log file) or an object which support <syswrite()> (like IO::Handle) or write() (like IO::Handle or File::Write::Rotate) or log (like Log::Dispatch::Output). If object supports log, it will be called like a Log::Dispatch::Output object, i.e. $obj->log(level=>'info', message=>"Log line ...\n"). Otherwise it will be called with the log line as the single argument.
write()
log
max_args_len => INT (default 1000)
Maximum number of characters of args to log. Args will be JSON-encoded and truncated to this value if too long. In the log file it will be printed as:
[args <LENGTH> <ARGS>]
max_resp_len => INT (default 1000)
Maximum number of characters of sub response to log. Response will be JSON-encoded and truncated to this value if too long. In the log file it will be printed as:
[resp <LENGTH> <ARGS>]
Please visit the project's homepage at https://metacpan.org/release/Perinci-Access-HTTP-Server.
Source repository is at https://github.com/sharyanto/perl-Perinci-Access-HTTP-Server.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Access-HTTP-Server
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2017, 2015, 2014, 2013, 2012, 2011 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Perinci::Access::HTTP::Server, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perinci::Access::HTTP::Server
CPAN shell
perl -MCPAN -e shell install Perinci::Access::HTTP::Server
For more information on module installation, please visit the detailed CPAN module installation guide.