Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/WineTestBot/Log.pm | 59 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 29 deletions(-)
diff --git a/testbot/lib/WineTestBot/Log.pm b/testbot/lib/WineTestBot/Log.pm index 49a7453bd..c5f00da8e 100644 --- a/testbot/lib/WineTestBot/Log.pm +++ b/testbot/lib/WineTestBot/Log.pm @@ -34,26 +34,28 @@ use WineTestBot::Config;
my $logfile; my $logprefix; -sub LogMsg(@) +sub SetupLogging() { - if (!defined $logfile) + require File::Basename; + $logprefix = File::Basename::basename($0); + $logprefix =~ s/.[^.]*$//; + my $oldumask = umask(002); + if (!open($logfile, ">>", "$LogDir/log")) { - require File::Basename; - $logprefix = File::Basename::basename($0); - $logprefix =~ s/.[^.]*$//; - my $oldumask = umask(002); - if (!open($logfile, ">>", "$LogDir/log")) - { - print STDERR "$logprefix:warning: could not open '$LogDir/log' for writing: $!\n"; - open($logfile, ">>&=", 2); - } - umask($oldumask); - - # Flush after each print - my $tmp=select($logfile); - $| = 1; - select($tmp); + print STDERR "$logprefix:warning: could not open '$LogDir/log' for writing: $!\n"; + open($logfile, ">>&=", 2); } + umask($oldumask); + + # Flush after each print + my $tmp=select($logfile); + $| = 1; + select($tmp); +} + +sub LogMsg(@) +{ + SetupLogging() if (!defined $logfile); print $logfile scalar localtime, " ", $logprefix, "[$$]: ", @_ if ($logfile); }
@@ -96,19 +98,18 @@ exec()-ing external tools so their error messages are not lost.
sub SetupRedirects() { - if (defined $logfile) + SetupLogging() if (!defined $logfile); + + if (open(STDERR, ">>&", $logfile)) + { + # Make sure stderr still flushes after each print + my $tmp = select(STDERR); + $| = 1; + select($tmp); + } + else { - if (open(STDERR, ">>&", $logfile)) - { - # Make sure stderr still flushes after each print - my $tmp=select(STDERR); - $| = 1; - select($tmp); - } - else - { - LogMsg "unable to redirect stderr to '$logfile': $!\n"; - } + LogMsg "unable to redirect stderr to '$logfile': $!\n"; } }