Subject: | Improving logging with autoflush |
Adding "autoflush" call to the log file handle would improve logging. Without this, the log file output is buffered. If the POE HTTP server is stopped before a buffer is flushed, then this logging is missed.
HTTPServer.pm
use FileHandle qw(autoflush);
# omitted code
sub create_server {
my $self = shift;
unless ( @{$self->handlers()} ) {
$self->{_debug}->("No handlers: setting NotFoundHandler for all\n");
$self->handlers( ['/' => new_handler('NotFoundHandler')] );
}
if ( defined($self->{_log_file}) ) {
$self->{_debug}->("Opening log: $self->{_log_file}\n");
open( $self->{_log_fh}, ">> $self->{_log_file}" ) ||
warn "Could not open log file '$self->{_log_file}' ($!)\n";
autoflush $self->{_log_fh}, 1; # suggestion here
}
$self->{_debug}->("Creating server component\n");
return
POE::Component::Server::TCP->new( Port => $self->port,
ClientInput => $self->_get_dispatcher,
ClientFilter => 'POE::Filter::HTTPD',
);
}
Message body is not shown because it is too large.