Dancer2...Capture(3)

✨ NAME ✨

okay bestie, so this page is the manual for Dancer2::Logger::Capture (from the Dancer2...Capture(3) section of the User Contributed Perl Documentation, iykyk) β€” and it's literally just about capturing dancer logs. that's the whole vibe. πŸ’–


🌸 VERSION 🌸

we're on version 2.2.1 rn, bestie. fresh off the press. ✨


πŸŽ€ SYNOPSIS πŸŽ€

so like, the absolute basics first:

set logger => "capture";

my $trap = dancer_app->logger_engine->trapper;
my $logs = $trap->read;

and here's a full worked-out real-world example, because we're not gatekeeping πŸ‘‘

use Test::More tests => 2;
use Dancer2;

set logger => 'capture';

warning "Danger!  Warning!";
debug   "I like pie.";

my $trap = dancer_app->logger_engine->trapper;

is_deeply $trap->read, [
    { level => "warning", message => "Danger!  Warning!" },
    { level => "debug",   message => "I like pie.", }
];

# each call to read cleans the trap
is_deeply $trap->read, [];
not me pointing out the comment: every single call to read cleans the trap. so once you read it, it's gone, fr fr. πŸ’€

πŸ’… DESCRIPTION πŸ’…

this is a logger class for Dancer2 that captures all logs into an object. it's giving ✨collector energy✨.

its main purpose? testing. that's the whole point, no cap. here's an example test:

use strict;
use warnings;
use Test::More;
use Plack::Test;
use HTTP::Request::Common;
use Ref::Util qw<is_coderef>;

{
    package App;
    use Dancer2;

    set log       => 'debug';
    set logger    => 'capture';

    get '/' => sub {
        log(debug => 'this is my debug message');
        log(core  => 'this should not be logged');
        log(info  => 'this is my info message');
    };
}

my $app = Dancer2->psgi_app;
ok( is_coderef($app), 'Got app' );

test_psgi $app, sub {
    my $cb = shift;

    my $res = $cb->( GET '/' );

    my $trap = App->dancer_app->logger_engine->trapper;

    is_deeply $trap->read, [
        { level => 'debug', message => 'this is my debug message' },
        { level => 'info',  message => 'this is my info message' },
    ];

    is_deeply $trap->read, [];
};

done_testing;

see how log(core => 'this should not be logged') just… doesn't show up in the trap? iconic behavior honestly. the core log didn't make the cut and that's so real of it. πŸ¦‹


πŸ”₯ METHODS πŸ”₯

trapper

returns the Dancer2::Logger::Capture::Trap object β€” the little guy you use to capture and read logs. that's your whole access point, bestie. 🫢


πŸ‘€ SEE ALSO πŸ‘€

go check these out if you want the full lore:

  • Dancer2::Core::Role::Logger
  • Dancer2::Logger::Capture::Trap

πŸ’œ AUTHOR πŸ’œ

Dancer Core Developers β€” the collective, the icons, the moment. πŸ‘‘


This software is copyright (c) 2026 by Alexis Sukrieh.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

important, bestie: that's the actual license text, so like, don't go rogue β€” same terms as the Perl 5 programming language system itself, periodt.

and that's the whole page!! πŸŽ€βœ¨ this was Dancer2...Capture(3), rendered with perl v5.42.3, dated 2026-09-20 β€” so if you're reading this on a date older than that, bestie, you're in a time warp πŸ’€ anyway ily, go capture some logs, slay πŸ’…πŸ’–πŸŒΈ

πŸ“¦ where this page comes from