Title: RotatingFileHandler does not rotate if backupCount is 0
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Juha.Lemmetti, python-dev, vinay.sajip
Priority: normal Keywords:

Created on 2015-01-23 10:37 by Juha.Lemmetti, last changed 2015-01-23 21:20 by python-dev. This issue is now closed.

Messages (4)
msg234552 - (view) Author: Juha Lemmetti (Juha.Lemmetti) Date: 2015-01-23 10:37
If RotatingFileHandler is initialized with backupCount 0, the file does not rotate but grows indefinitely. This is not self-evident from the documentation.

Suggestion: either rotate (discard) the log if backupCount==0 or mention the current operation the documentation. The former leaves the user with only one log message at the worst case. 

In the latter case, the documentation can be modified to explicitly mention what the result will be if backupCount is left to its default value of 0, i.e. that the RotatingFileHandler will grow the file indefinitely regardless of the value of maxBytes value. The default value for the backupCount could also be modified, as the default value does nothing.

Tested with Windows-Python2.7, Linux-Python 3.3.2+ (Ubuntu-14.04). Can be reproduced with a simple logging example with backupCount == 0 and maxBytes > 0
msg234575 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2015-01-23 20:07
The default parameters for backupCount and maxBytes are both shown as 0.

The first paragraph ends with "By default, the file grows indefinitely."

The second paragraph says, "If backupCount is non-zero, the system will save old log files by appending the extensions ‘.1’, ‘.2’".

Together, these should indicate that the file will grow indefinitely (and not rotate) if backupCount is left at 0.
msg234581 - (view) Author: Juha Lemmetti (Juha.Lemmetti) Date: 2015-01-23 20:39
What You point out is true. However, I saw a bug in code where RotatingFileHandler was used, and I had to check the operation using a small test program.

For maxBytes, it is explicitly stated that when the value is 0, rollover never occurs. It wouldn't hurt to have the same text for backupCount in the documentation, just for clarity.
msg234585 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-23 21:20
New changeset 0375eb71d75e by Vinay Sajip in branch '2.7':
Issue #23305: clarified RotatingFileHandler documentation.

New changeset 93888975606b by Vinay Sajip in branch '3.4':
Issue #23305: clarified RotatingFileHandler documentation.

New changeset 67ebf7ae686d by Vinay Sajip in branch 'default':
Closes #23305: Merged documentation fix from 3.4.
Date User Action Args
2015-01-23 21:20:19python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg234585

resolution: fixed
stage: resolved
2015-01-23 20:39:16Juha.Lemmettisetstatus: pending -> open

messages: + msg234581
2015-01-23 20:07:45vinay.sajipsetstatus: open -> pending

messages: + msg234575
2015-01-23 14:43:05r.david.murraysetversions: + Python 3.5, - Python 3.3
2015-01-23 10:37:03Juha.Lemmetticreate