NAME

Plack::Middleware::SubSpec::LogAccess - Log request

VERSION

version 0.10

SYNOPSIS

# In app.psgi
use Plack::Builder;

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

DESCRIPTION

This middleware forwards the request to given app and logs request. Only requests which have executed commands (has $env->{'ss.start_command_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
pm://MyModule/my_func [args 14 {"name":"val"}] [resp 12 [200,"OK",1]]
2.123ms 5.947ms

The second last time is time spent executing the command (in this case, calling the subroutine), and the last time is time spent for the whole request (from client connect until response is sent).

CONFIGURATION

  • log_path

    Path to log file. Log file will be opened in append-mode.

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

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 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.