clean up debug logger

This commit is contained in:
Graham Knop 2010-04-13 20:43:00 -05:00
parent 907a148313
commit 30b7e4bdb3
3 changed files with 47 additions and 117 deletions

View file

@ -3,6 +3,7 @@ use strict;
use parent qw(Plack::Middleware);
use WebGUI::Config;
use WebGUI::Session;
use WebGUI::Utility ();
use Try::Tiny;
use Plack::Middleware::StackTrace;
use Plack::Middleware::Debug;
@ -37,7 +38,7 @@ sub call {
weaken $self->{config};
my $config = $self->config or die 'Mandatory config parameter missing';
# Logger fallback
if (!$env->{'psgix.logger'}) {
$app = Plack::Middleware::SimpleLogger->wrap( $app );
@ -66,7 +67,7 @@ sub call {
# Perhaps I'm being paranoid..
weaken $session->{_config};
my $debug = $session->log->canShowDebug;
my $debug = $self->canShowDebug($env);
if ($debug) {
$app = Plack::Middleware::StackTrace->wrap($app);
$app = Plack::Middleware::Debug->wrap( $app,
@ -112,4 +113,22 @@ sub call {
);
}
sub canShowDebug {
my $self = shift;
my $env = shift;
my $session = $env->{'webgui.session'};
my $canShow = $session->setting->get("showDebug");
return
unless $canShow;
my $ips = $session->setting->get('ipDebug');
return 1
if $ips eq '';
$ips =~ s/\s+//g;
my @ips = split /,/, $ips;
my $ok = WebGUI::Utility::isInSubnet($session->env->getIp, [ @ips ] );
return $ok;
}
1;