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
45
46
47
48
49
50
51
52
53
54
55
56
|
package Plack::Middleware::Debug::Dancer::Logger;
# ABSTRACT: Log message from you Dancer's application
use strict;
use warnings;
use parent qw(Plack::Middleware::Debug::Base);
use Dancer::Logger;
use Class::Method::Modifiers qw(install_modifier);
# # XXX Not thread/Coro/AE safe. Should use $c->env or something
my $psgi_env;
install_modifier 'Dancer::Logger', 'before', 'error' => sub {
_add_log( 'error', @_ );
};
install_modifier 'Dancer::Logger', 'before', 'warning' => sub {
_add_log( 'warning', @_ );
};
install_modifier 'Dancer::Logger', 'before', 'debug' => sub {
_add_log( 'debug', @_ );
};
sub _add_log {
my ( $level, $msg ) = @_;
push @{ $psgi_env->{'plack.middleware.dancer_log'} }, $level, $msg;
}
sub run {
my ( $self, $env, $panel ) = @_;
$psgi_env = $env;
return sub {
my $res = shift;
$panel->title('Dancer::Logger');
$panel->nav_subtitle('Dancer::Logger');
my $logs = delete $env->{'plack.middleware.dancer_log'}
if $env->{'plack.middleware.dancer_log'};
$panel->content( sub { $self->render_list_pairs($logs) } ) if $logs;
$psgi_env = undef;
};
}
1;
=head1 SYNOPSIS
To activate this panel:
plack_middlewares:
Debug:
- panels
-
- Dancer::Logger
|