Autoflush log filehandles
This commit is contained in:
parent
4e1e73f284
commit
d1b027a3ff
14
ACU/Log.pm
14
ACU/Log.pm
@ -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){
|
||||
|
Reference in New Issue
Block a user