Skip to content

Commit

Permalink
Logging fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
patspam committed Apr 13, 2010
1 parent 42c1a8e commit 7ef963e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -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:

Expand Down
12 changes: 7 additions & 5 deletions benchmark.pl
@@ -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;
};
2 changes: 1 addition & 1 deletion eg/dev.localhost.localdomain.fcgi
@@ -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);
6 changes: 6 additions & 0 deletions lib/WebGUI/Middleware/Session.pm
Expand Up @@ -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 );

Expand All @@ -33,6 +34,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 );
Expand Down
19 changes: 18 additions & 1 deletion lib/WebGUI/Session/ErrorHandler.pm
Expand Up @@ -274,7 +274,24 @@ Returns a reference to the logger.

sub getLogger {
my $self = shift;
return $self->session->request->logger;
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};
}
}


Expand Down

0 comments on commit 7ef963e

Please sign in to comment.