package Plack::Middleware::Timed::Logger; use 5.16.0; use strict; use warnings; use parent qw(Plack::Middleware); use Timed::Logger; =head1 NAME Plack::Middleware::Timed::Logger - Expose a Timed::Logger Instance in Middleware =head1 VERSION Version 0.0.5 =cut our $VERSION = '0.0.5'; =head1 SYNOPSIS use Plack::Builder; builder { enable 'Timed::Logger'; $app; }; =head1 DESCRIPTION L does one thing, it places an instance of L into the C<$env> under C. A new instance is created for each incoming request. This middleware is intended to act as a bridge between L, which holds log of the events, with a reporting tool such as seen in L. Unless you are building some custom logging tools, you probably just want to use the existing debug panel (L) rather than building something custom around this middleware. If you are using Dancer to build your web application you may want to use L to help you to bridge Dancer's conrollers with this middleware. This module was inspired by L. =head1 SUBROUTINES This middleware defines the following public subroutines =head2 PSGI_KEY Returns the PSGI C<$env> key under which you'd expect to find an instance of L. =head2 get_logger_from_env Given a L C<$env>, returns a L. You should use this in your code that is trying to access the logger. For example: use Plack::Middleware::Timed::Logger; sub logger { my ($self, $env) = @_; Plack::Middleware::Timed::Logger->get_logger_from_env($env); } This function creates a new instance of L if one doesn't exist already. This is the officially supported interface for extracting a L from a L request. =head2 call An callback used by Plack to call this middleware. =cut sub PSGI_KEY {'plack.middleware.timed.logger'} sub get_logger_from_env { my ($self, $env) = @_; #Create a new logger if one is not defined already $env->{+PSGI_KEY} ||= Timed::Logger->new(); return $env->{+PSGI_KEY}; } sub call { my ($self, $env) = @_; $env->{+PSGI_KEY} ||= Timed::Logger->new(); $self->app->($env); } =head1 SEE ALSO L, L, L =head1 AUTHOR Nikolay Martynov, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Plack::Middleware::Timed::Logger You can also look for information at: =over 4 =item * RT: CPAN's request tracker (report bugs here) L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS Logan Bell and Belden Lyman. =head1 LICENSE AND COPYRIGHT Copyright 2013 Nikolay Martynov and Shutterstock Inc (http://shutterstock.com). All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See L for more information. =cut 1; # End of Plack::Middleware::Timed::Logger