Item11157: PlainFile logger rotates logs on localtime, not gmtime.

Priority: CurrentState: AppliesTo: Component: WaitingFor:
Normal Closed Engine FoswikiLogger  
It appears that the code to convert the time to the year/month uses localtime, but logging is in gmt. So depending on where the test it run, it will fail.

Made following changes to get Logger.pm tests working here:

diff --git a/core/lib/Foswiki/Logger/PlainFile.pm b/core/lib/Foswiki/Logger/PlainFile.pm
index 49aab0c..77732d2 100644
--- a/core/lib/Foswiki/Logger/PlainFile.pm
+++ b/core/lib/Foswiki/Logger/PlainFile.pm
@@ -239,7 +239,7 @@ sub _getLogForLevel {
 
 sub _time2month {
     my $time = shift;
-    my @t    = localtime($time);
+    my @t    = gmtime($time);
     $t[5] += 1900;
     return sprintf( '%0.4d%0.2d', $t[5], $t[4] + 1 );
 }
-- GeorgeClark - 30 Sep 2011

and in the Logger.pm test

@@ -210,7 +226,7 @@ sub verify_rotate {
 
     $Foswiki::Logger::PlainFile::dontRotate = 1;
 
-    my $then = Foswiki::Time::parseTime("2000-02-01");
+    my $then = Foswiki::Time::parseTime("2000-02-01T00:00Z");
 
     $plainFileTestTime = $then;
     $mode              = 0777;
@@ -224,7 +240,7 @@ sub verify_rotate {
     $this->assert( !-e $lfn );
 
     # Create the log, the entry should be stamped at $then - 1000 (last month)
-    $plainFileTestTime = $then - 1000;
+    $plainFileTestTime = Foswiki::Time::parseTime("2000-01-31T23:59Z");
     $logger->log( 'info', 'Nil carborundum illegitami' );
 
     # fake the modify time
@@ -254,7 +270,7 @@ sub verify_rotate {
     $this->assert( open( F, '<', $backup ) );
     $e = <F>;
     $this->assert_equals(
-        "| 2000-01-31T23:43:20Z info | Nil carborundum illegitami |\n", $e );
+        "| 2000-01-31T23:59:00Z info | Nil carborundum illegitami |\n", $e );
     close(F);
 
     *Foswiki::Logger::PlainFile::_time = $timecache;


Crawford - any concerns? Does this make sense? Also any reason the Logger tests don't run as part of the FoswikiSuite?

-- GeorgeClark - 30 Sep 2011

Looks like the test needs to be named LoggerTests to be included in the FoswikiSuite automatically.

-- GeorgeClark - 30 Sep 2011

That makes sense. IMO all time handling - with the possible exception of time display - should be handled in gmtime.

-- CrawfordCurrie - 01 Oct 2011
 

ItemTemplate edit

Summary PlainFile logger rotates logs on localtime, not gmtime.
ReportedBy GeorgeClark
Codebase 1.1.3, trunk
SVN Range
AppliesTo Engine
Component FoswikiLogger
Priority Normal
CurrentState Closed
WaitingFor
Checkins Foswikirev:12668 Foswikirev:12669
TargetRelease patch
ReleasedIn 1.1.4
Topic revision: r6 - 17 Dec 2011, GeorgeClark
 
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. see CopyrightStatement. Creative Commons License