Permalink
Browse files

Item14035: Compare log for rotate using server time

Leaving TRACE enabled for now to catch debugging on foswiki.org
  • Loading branch information...
1 parent ee4741b commit 649bc067a7fe3d38d02032f6af920f51631b3a0c @gac410 gac410 committed Apr 1, 2016
Showing with 9 additions and 14 deletions.
  1. +9 −14 core/lib/Foswiki/Logger/PlainFile.pm
@@ -61,7 +61,7 @@ This logger implementation maps groups of levels to a single logfile, viz.
use Foswiki::Time qw(-nofoswiki);
-use constant TRACE => 0;
+use constant TRACE => 1;
# Map from a log level to the root of a log file name
our %LEVEL2LOG = (
@@ -276,14 +276,6 @@ sub _getLogsForLevel {
return ( keys %logs );
}
-sub _time2month {
- my $time = shift;
- return undef unless ( defined $time );
- my @t = localtime($time);
- $t[5] += 1900;
- return sprintf( '%0.4d%0.2d', $t[5], $t[4] + 1 );
-}
-
# See if the log needs to be rotated. If the log was last modified
# last month, we need to rotate it.
sub _rotate {
@@ -296,7 +288,7 @@ sub _rotate {
return if ( $now < $nextCheckDue{$level} );
# Work out the current month
- my $curMonth = _time2month($now);
+ my $curMonth = Foswiki::Time::formatTime( $now, '$year$mo', 'servertime' );
print STDERR "Current MONTH = $curMonth\n" if (TRACE);
# After this check, don't check again for a month.
@@ -309,17 +301,20 @@ sub _rotate {
else {
$m = sprintf( '%0.2d', $m );
}
- $nextCheckDue{$level} = Foswiki::Time::parseTime("$y-$m-01");
- print STDERR "Next log check due $nextCheckDue{$level} for $level\n"
+ $nextCheckDue{$level} =
+ Foswiki::Time::parseTime( "$y-$m-01", 1 ); # use local (server) time.
+ print STDERR
+ "Next log check due $nextCheckDue{$level} for $level, now: $now\n"
if (TRACE);
# If there's no existing log, there's nothing to rotate
return unless -e $log;
# Check when the log was last modified. If it was in the previous
# month, if may need to be rotated.
- my @stat = _stat($log);
- my $modMonth = _time2month( $stat[9] );
+ my @stat = _stat($log);
+ my $modMonth =
+ Foswiki::Time::formatTime( $stat[9], '$year$mo', 'servertime' );
print STDERR "compare $modMonth, $curMonth\n" if (TRACE);
return if ( $modMonth == $curMonth );

0 comments on commit 649bc06

Please sign in to comment.