File: synopsis.psgi

package info (click to toggle)
libplack-middleware-logerrors-perl 0.003-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 223; sh: 6; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 602 bytes parent folder | download
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
use strict;
use warnings;

# try this out with:
#   plackup examples/synopsis.psgi &
#   curl http://localhost:5000/hi

use Log::Dispatch;
use Plack::Builder;

my $logger = Log::Dispatch->new(
    outputs => [
        [ File => filename => 'example.log', min_level => 'debug' ],
    ],
);

my $app = sub {
    my $env = shift;

    # this will go to our configured logger
    # and conveniently enough, so does the access log!
    $env->{'psgi.errors'}->print("oh noes!\n");

    [ 200, [], [ 'hello' ] ];
};

builder {
    enable 'LogDispatch', logger => $logger;
    enable 'LogErrors';
    $app;
}