epita-std
/
ACU
Archived
1
0
Fork 0

Autoflush log filehandles

This commit is contained in:
Mercier Pierre-Olivier 2013-12-05 00:54:30 +01:00
parent 4e1e73f284
commit d1b027a3ff
1 changed files with 12 additions and 2 deletions

View File

@ -52,12 +52,17 @@ sub log
if (!$log_fd && $log_file) {
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 ";
}
if ($level <= $save_level and $log_fd)
{
local $| = 1;
print $log_fd strftime("%a %b %e %H:%M:%S %Y", localtime), " ", levelstr($level), " ";
if ($level == TRACE) {
@ -102,12 +107,17 @@ The lerdorf project",
sendmail($mail);
}
if ($level <= $display_level) {
if ($level <= $display_level)
{
$|++; # Autoflush STDOUT
if ($level == PENDING) {
print STDERR (leveldisp($level), @_, RESET, "\r");
} else {
say STDERR (leveldisp($level), @_, RESET);
}
$|--; # Disable autoflush
}
if ($fatal_warn && $level <= WARN){