[issue1836] 'weekly' rotating logging file rotation incorrect

Kathryn M Kowalski report at bugs.python.org
Fri Jan 18 21:30:29 CET 2008


Kathryn M Kowalski added the comment:

I did not put suggested code in - walking through it and counting days 
on my fingers I don't think it works.

If the desired rollover day is Tuesday (self.dayOfWeek = 1) and today 
is Tuesday (day = 1) then self.rolloverAt is the seconds to midnight as 
if daysToWait =0, and it rolls over at midnight Tuesday.  However if 
the desired rollover day is Tuesday (self.dayOfWeek = 1) and today is 
Monday (day = 0) then daysToWait = 0 again.  It rolls over on Monday at 
midnight - not Tuesday at midnight.

If the desired rollover day is Tuesday (self.dayOfWeek = 1) and today 
is Wednesday (day = 2) then daysToWait = 5.  It also rolls over on 
Monday at midnight - not Tuesday at midnight.

Changing it to:
    day = t[6] # 0 is Monday
    if day != self.dayOfWeek:
        if day < self.dayOfWeek:
            daysToWait = self.dayOfWeek - day
        else:
            daysToWait = 6 - day + self.dayOfWeek + 1

would make it equivalent to what I have running and appears to work. 
(Always rolls (ends) on day specified at midnight.)

Alternatively, if you wanted to change it so the log starts on the day 
specified you could just get rid of "if day != self.dayOfWeek:" from 
your code.

if when.startswith('W'):
    day = t[6] # 0 is Monday
    if day < self.dayOfWeek:
        daysToWait = self.dayOfWeek - day - 1
    else:
        daysToWait = 6 - day + self.dayOfWeek
    self.rolloverAt = self.rolloverAt + (daysToWait * (60 * 60 * 24))

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1836>
__________________________________


More information about the Python-bugs-list mailing list