summaryrefslogtreecommitdiff
path: root/lib/Dancer/Logger/PSGI.pm
blob: 9134e2b778b7e0e06bc30dc45cbc12826d9f235f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package Dancer::Logger::PSGI;

# ABSTRACT: PSGI Log handler for Dancer

use strict;
use warnings;

our $VERSION = '0.01';

use Dancer::SharedData;
use base 'Dancer::Logger::Abstract';

sub init {}

sub _log {
    my ( $self, $level, $message ) = @_;
    my $request = Dancer::SharedData->request;
    if ( $request->{env}->{'psgix.logger'} ) {
        $request->{env}->{'psgix.logger'}
            ->( { level => $level, message => $message } );
    }
}

1;

=head1 SYNOPSIS

In your Dancer's configuration file:

    logger: PSGI

In your application

    warning "this is a warning"

In your app.psgi

    $app = builder { enable "ConsoleLogger"; $app; }

With L<Plack::Middleware::ConsoleLogger>, all your log will be send to the javascript console of your browser.

=head1 DESCRIPTION

This class is an interface between your Dancer's application and B<psgix.logger>. Message will be logged in whatever logger you decided to use in your L<Plack> handler. If no logger is defined, nothing will be logged.