Module: tools Branch: master Commit: 9267a1169b5d362c9499683b35a74a1454d4d309 URL: http://source.winehq.org/git/tools.git/?a=commit;h=9267a1169b5d362c9499683b3...
Author: Francois Gouget fgouget@codeweavers.com Date: Thu Oct 4 14:40:08 2012 +0200
testbot/lib: Tweak Log.pm to not open the log file for every message.
Also issue a meaningful message to stderr if we cannot open the log file.
---
testbot/lib/WineTestBot/Log.pm | 26 +++++++++++++++++++------- 1 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/testbot/lib/WineTestBot/Log.pm b/testbot/lib/WineTestBot/Log.pm index a6762cc..6883968 100644 --- a/testbot/lib/WineTestBot/Log.pm +++ b/testbot/lib/WineTestBot/Log.pm @@ -32,16 +32,28 @@ require Exporter; @ISA = qw(Exporter); @EXPORT = qw(&LogMsg);
-sub LogMsg +my $logfile; +sub LogMsg(@) { - my $oldumask = umask(002); - my $LOGFILE; - if (open LOGFILE, ">>$LogDir/log") + if (!defined $logfile) { - print LOGFILE scalar localtime, " ", @_; - close LOGFILE; + my $oldumask = umask(002); + if (open($logfile, ">>", "$LogDir/log")) + { + # Flush after each print + my $tmp=select($logfile); + $| = 1; + select($tmp); + } + else + { + require File::Basename; + print STDERR File::Basename::basename($0), ":warning: could not open '$LogDir/log' for writing: $!\n"; + $logfile = undef; + } + umask($oldumask); } - umask($oldumask); + print $logfile scalar localtime, " ", @_ if ($logfile); }
1;