shouldRollover overwrites backup file in 'w' mode

Bug #1377587 reported by Nir Arad
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Concurrent Log Handler for Python
New
Undecided
Unassigned

Bug Description

shouldRollover function calls _shouldRollover() twice.

    if self._shouldRollover(): # First check
           # if some other process already did the rollover we might
           # checked log.1, so we reopen the stream and check again on
           # the right log file
           self.stream.close()
           self._openFile(self.mode)
           return self._shouldRollover()

After the first check, if we should rollover, self._openFile will open the file again with the same mode.
However, if the mode is 'w' then the file is overwritten.

Also, because we overwritten the file, the second call to _shouldRollover will always return false.

Revision history for this message
Nir Arad (nira-p) wrote :

I've looked into RotatingFileHandler.__init__() and they added this:

        # If rotation/rollover is wanted, it doesn't make sense to use another
        # mode. If for example 'w' were specified, then if there were multiple
        # runs of the calling application, the logs from previous runs would be
        # lost if the 'w' is respected, because the log file would be truncated
        # on each run.

        if maxBytes > 0:
            mode = 'a'

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.