NAME

Plack::Middleware::PeriAHS::LogAccess - Log request

VERSION

version 0.39

SYNOPSIS

# In app.psgi
use Plack::Builder;

builder {
    enable "PeriAHS::LogAccess", dest => "/path/to/api-access.log";
}

DESCRIPTION

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.

CONFIGURATION

  • 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.

  • 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>]

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Perinci-Access-HTTP-Server.

SOURCE

Source repository is at https://github.com/sharyanto/perl-Perinci-Access-HTTP-Server.

BUGS

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.

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.