Logging fallback

This commit is contained in:
Patrick Donelan 2010-04-13 17:27:18 -04:00
parent 42c1a8e149
commit 7ef963e74f
5 changed files with 33 additions and 8 deletions

2
README
View file

@ -2,7 +2,7 @@ This is the PSGI branch of WebGUI8
Currently, the best performance is achieved via:
plackup -E none -s Starman --workers 10
plackup -E none -s Starman --workers 10 --disable-keepalive
You can benchmark your server via:

View file

@ -1,17 +1,19 @@
# Little script used to run benchmarks against dev.localhost.localdomain
#
# To profile, run "perl -d:NYTProf benchmark.pl"
use Devel::Leak::Object qw(GLOBAL_bless);
$Devel::Leak::Object::TRACKSOURCELINES = 1;
use lib '/data/WebGUI/lib';
use WebGUI;
use Plack::Test;
use Plack::Builder;
use HTTP::Request::Common;
my $wg = WebGUI->new( root => '/data/WebGUI', site => 'dev.localhost.localdomain.conf' );
my $app = $wg->psgi_app;
my $app = builder {
enable '+WebGUI::Middleware::Session', config => $wg->config;
$wg;
};
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->( GET "/" );
} for 1..100;
$cb->( GET "/" ) for 1..1000;
};

View file

@ -1,5 +1,5 @@
#!/usr/bin/perl
use Plack::Server::FCGI;
my $app = Plack::Util::load_psgi("/data/WebGUI/etc/dev.localhost.localdomain.psgi");
my $app = Plack::Util::load_psgi("../app.psgi");
Plack::Server::FCGI->new->run($app);

View file

@ -8,6 +8,7 @@ use Plack::Middleware::StackTrace;
use Plack::Middleware::Debug;
use WebGUI::Middleware::HTTPExceptions;
use Plack::Middleware::ErrorDocument;
use Plack::Middleware::SimpleLogger;
use Plack::Util::Accessor qw( config error_docs );
@ -34,6 +35,11 @@ sub call {
my $app = $self->app;
my $config = $self->config or die 'Mandatory config parameter missing';
# Logger fallback
if (!$env->{'psgix.logger'}) {
$app = Plack::Middleware::SimpleLogger->wrap( $app );
}
my $session = try {
$env->{'webgui.session'} = WebGUI::Session->open( $config->getWebguiRoot, $config, $env );
};

View file

@ -274,7 +274,24 @@ Returns a reference to the logger.
sub getLogger {
my $self = shift;
if ($self->session->request) {
return $self->session->request->logger;
} else {
# Thanks to Plack, wG has been decoupled from Log4Perl
# However when called outside a web context, we currently still fall back to Log4perl
# (pending a better idea)
if (!$self->{_logger}) {
Log::Log4perl->init_once( $self->session->config->getWebguiRoot."/etc/log.conf" );
my $logger = Log::Log4perl->get_logger($self->session->config->getFilename);
$self->{_logger} = sub {
my $args = shift;
my $level = $args->{level};
$logger->$level($args->{message});
};
}
return $self->{_logger};
}
}