Skip to content

Instantly share code, notes, and snippets.

@grantm
Created Jul 13, 2010
Embed
What would you like to do?
diff --git a/lib/Plack/Runner.pm b/lib/Plack/Runner.pm
index de83a23..70b58b6 100644
--- a/lib/Plack/Runner.pm
+++ b/lib/Plack/Runner.pm
@@ -50,6 +50,7 @@ sub parse_options {
'r|reload' => sub { $self->{loader} = "Restarter" },
'R|Reload=s' => sub { $self->{loader} = "Restarter"; $self->loader->watch(split ",", $_[1]) },
'L|loader=s' => \$self->{loader},
+ "access-log=s" => \$self->{access_log},
"h|help" => \$self->{help},
"v|version" => \$self->{version},
);
@@ -191,7 +192,7 @@ sub prepare_devel {
$app = $self->apply_middleware($app, 'Lint');
$app = $self->apply_middleware($app, 'StackTrace');
- unless ($ENV{GATEWAY_INTERFACE}) {
+ if (!$ENV{GATEWAY_INTERFACE} and !$self->{access_log}) {
$app = $self->apply_middleware($app, 'AccessLog', logger => sub { print STDERR @_ });
}
@@ -241,6 +242,14 @@ sub run {
$app = $self->prepare_devel($app);
}
+ if ($self->{access_log}) {
+ open my $logfh, ">>", $self->{access_log}
+ or die "open($self->{access_log}): $!";
+ my $io = IO::Handle->new_from_fd(fileno($logfh), 'w');
+ $io->autoflush(1);
+ $app = $self->apply_middleware($app, 'AccessLog', logger => sub { $io->print( @_ ) });
+ }
+
my $loader = $self->loader;
$loader->preload_app($app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment