Plack::Middleware::AccessLog::Structured - Access log middleware which creates structured log messages
version 0.001002
use Plack::Middleware::AccessLog::Structured; Plack::Middleware::AccessLog::Structured->wrap($app, callback => sub { my ($env, $message) = @_; $message->{foo} = 'bar'; return $message; }, extra_field => { 'some.application.field' => 'log_field', 'some.psgi-env.field' => 'another_log_field', }, );
Plack::Middleware::AccessLog::Structured is a Plack::Middleware which creates and logs structured messages.
If the above example is used with a basic PSGI application that simply returns ok, the following, JSON-encoded message would be logged (on one log line):
ok
{ "remote_addr": "127.0.0.1", "request_method": "GET", "request_uri": "/", "server_protocol": "HTTP/1.1", "remote_user": null, "http_referer": null, "http_user_agent": "Mozilla/5.0 [...]", "request_duration": 0.0679492950439453, "epochtime": 1348687439.49608, "date": "2012-09-26T19:23:59.496Z", "hostfqdn": "some.hostname.tld", "hostname": "some", "http_host": "localhost:5000", "pid": 4777, "log_field": null, "another_log_field": null, "foo": "bar", "response_status": 200, "content_length": 2, "content_type": "text/plain", "class": "Plack::Middleware::AccessLog::Structured" }
Constructor, creates new instance.
This method expects its parameters as a hash reference.
Optional callback that can be used to modify the log message before it is encoded and logged. Gets the PSGI environment and the message as parameters and must return the possibly modified message.
Optional hash reference with a mapping from PSGI environment keys to keys in the log message. If passed, values from the PSGI environment will be copied to the corresponding fields in the log message, using this mapping.
A callback to pass the JSON-encoded log messages to. By default, log messages are printed to the psgi.errors output stream.
psgi.errors
A fresh instance of the middleware.
Specialized call method.
call
Plack::Middleware
Log::Message::Structured which inspired some of the fields in the log message.
Manfred Stock <mstock@cpan.org>
This software is copyright (c) 2018 by Manfred Stock.
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 Plack::Middleware::AccessLog::Structured, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::AccessLog::Structured
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::AccessLog::Structured
For more information on module installation, please visit the detailed CPAN module installation guide.