Archived
1
0

Autoflush log filehandles

This commit is contained in:
Mercier Pierre-Olivier 2013-12-05 00:54:30 +01:00
parent 4e1e73f284
commit d1b027a3ff

View File

@ -52,12 +52,17 @@ sub log
if (!$log_fd && $log_file) { if (!$log_fd && $log_file) {
open ($log_fd, ">>", $log_file) or croak("Unable to open log ($log_file) file for writing"); open ($log_fd, ">>", $log_file) or croak("Unable to open log ($log_file) file for writing");
# Enable autoflush for the log file
my $previous_default = select($log_fd);
$|++;
select($previous_default);
say $log_fd strftime("%a %b %e %H:%M:%S %Y", localtime), " START new logging session "; say $log_fd strftime("%a %b %e %H:%M:%S %Y", localtime), " START new logging session ";
} }
if ($level <= $save_level and $log_fd) if ($level <= $save_level and $log_fd)
{ {
local $| = 1;
print $log_fd strftime("%a %b %e %H:%M:%S %Y", localtime), " ", levelstr($level), " "; print $log_fd strftime("%a %b %e %H:%M:%S %Y", localtime), " ", levelstr($level), " ";
if ($level == TRACE) { if ($level == TRACE) {
@ -102,12 +107,17 @@ The lerdorf project",
sendmail($mail); sendmail($mail);
} }
if ($level <= $display_level) { if ($level <= $display_level)
{
$|++; # Autoflush STDOUT
if ($level == PENDING) { if ($level == PENDING) {
print STDERR (leveldisp($level), @_, RESET, "\r"); print STDERR (leveldisp($level), @_, RESET, "\r");
} else { } else {
say STDERR (leveldisp($level), @_, RESET); say STDERR (leveldisp($level), @_, RESET);
} }
$|--; # Disable autoflush
} }
if ($fatal_warn && $level <= WARN){ if ($fatal_warn && $level <= WARN){