File: log4perl.t

package info (click to toggle)
libplack-perl 0.9989-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,556 kB
  • sloc: perl: 6,890; python: 6; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,051 bytes parent folder | download | duplicates (10)
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
use strict;
use Plack::Test;
use Test::Requires qw(Log::Log4perl);

use Test::More;
use Plack::Middleware::Log4perl;
use HTTP::Request::Common;

my $test_file = "t/Plack-Middleware/log4perl.log";

my $conf = <<CONF;
log4perl.logger.plack.test = INFO, Logfile
log4perl.appender.Logfile = Log::Log4perl::Appender::File
log4perl.appender.Logfile.filename = $test_file
log4perl.appender.Logfile.layout   = Log::Log4perl::Layout::SimpleLayout
CONF

Log::Log4perl::init(\$conf);

my $app = sub {
    my $env = shift;
    $env->{'psgix.logger'}->({ level => "debug", message => "This is debug" });
    $env->{'psgix.logger'}->({ level => "info", message => "This is info" });
    return [ 200, [], [] ];
};

$app = Plack::Middleware::Log4perl->wrap($app, category => 'plack.test');

test_psgi $app, sub {
    my $cb = shift;
    my $res = $cb->(GET "/");

    my $log = do {
        open my $fh, "<", $test_file;
        join '', <$fh>;
    };

    like $log, qr/INFO - This is info/;
    unlike $log, qr/debug/;
};

END { unlink $test_file }

done_testing;