1Dancer2::Logger::CapturUes(e3r)Contributed Perl DocumentDaatnicoenr2::Logger::Capture(3)
2
3
4

NAME

6       Dancer2::Logger::Capture - Capture dancer logs
7

VERSION

9       version 0.300000
10

SYNOPSIS

12       The basics:
13
14           set logger => "capture";
15
16           my $trap = dancer_app->logger_engine->trapper;
17           my $logs = $trap->read;
18
19       A worked-out real-world example:
20
21           use Test::More tests => 2;
22           use Dancer2;
23
24           set logger => 'capture';
25
26           warning "Danger!  Warning!";
27           debug   "I like pie.";
28
29           my $trap = dancer_app->logger_engine->trapper;
30
31           is_deeply $trap->read, [
32               { level => "warning", message => "Danger!  Warning!" },
33               { level => "debug",   message => "I like pie.", }
34           ];
35
36           # each call to read cleans the trap
37           is_deeply $trap->read, [];
38

DESCRIPTION

40       This is a logger class for Dancer2 which captures all logs to an
41       object.
42
43       It's primary purpose is for testing. Here is an example of a test:
44
45           use strict;
46           use warnings;
47           use Test::More;
48           use Plack::Test;
49           use HTTP::Request::Common;
50           use Ref::Util qw<is_coderef>;
51
52           {
53               package App;
54               use Dancer2;
55
56               set log       => 'debug';
57               set logger    => 'capture';
58
59               get '/' => sub {
60                   log(debug => 'this is my debug message');
61                   log(core  => 'this should not be logged');
62                   log(info  => 'this is my info message');
63               };
64           }
65
66           my $app = Dancer2->psgi_app;
67           ok( is_coderef($app), 'Got app' );
68
69           test_psgi $app, sub {
70               my $cb = shift;
71
72               my $res = $cb->( GET '/' );
73
74               my $trap = App->dancer_app->logger_engine->trapper;
75
76               is_deeply $trap->read, [
77                   { level => 'debug', message => 'this is my debug message' },
78                   { level => 'info',  message => 'this is my info message' },
79               ];
80
81               is_deeply $trap->read, [];
82           };
83
84           done_testing;
85

METHODS

87   trapper
88       Returns the Dancer2::Logger::Capture::Trap object used to capture and
89       read logs.
90

SEE ALSO

92       Dancer2::Core::Role::Logger, Dancer2::Logger::Capture::Trap
93

AUTHOR

95       Dancer Core Developers
96
98       This software is copyright (c) 2019 by Alexis Sukrieh.
99
100       This is free software; you can redistribute it and/or modify it under
101       the same terms as the Perl 5 programming language system itself.
102
103
104
105perl v5.30.1                      2020-01-29       Dancer2::Logger::Capture(3)
Impressum