This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: TimedRotatingFileHandler forces "write" mode, should use "append"
Type: resource usage Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: axil, hynek, python-dev, richard, vinay.sajip
Priority: normal Keywords:

Created on 2012-10-16 05:05 by richard, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py axil, 2013-12-10 21:00 Snippet demonstrating the issue
Messages (3)
msg173016 - (view) Author: Richard Jones (richard) * (Python committer) Date: 2012-10-16 05:05
The RotatingFileHandler classes force the open() mode of the new log file to be "w" even though it is initially defaulted to "a" in doRollover() methods:

        self.mode = 'w'
        self.stream = self._open()

This can cause problems in systems that have multiple programs writing to the log file; they can both end up opening the new file in "w" mode and then there's loss of data.

I cannot think of a reason why "w" should be forced in this manner.

The fix is to remove the "self.mode = 'w'" line from the two doRollover() methods.
msg173020 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-16 09:33
New changeset 6fcfe701502b by Vinay Sajip in branch '2.7':
Issue #16244: Remove file mode overrides.
http://hg.python.org/cpython/rev/6fcfe701502b

New changeset 5e770555be62 by Vinay Sajip in branch '3.2':
Issue #16244: Remove file mode overrides.
http://hg.python.org/cpython/rev/5e770555be62

New changeset 4f1287be26a6 by Vinay Sajip in branch '3.3':
Issue #16244: Merged change from 3.2.
http://hg.python.org/cpython/rev/4f1287be26a6

New changeset c20b0b5590db by Vinay Sajip in branch 'default':
Closes #16244: Merged change from 3.3.
http://hg.python.org/cpython/rev/c20b0b5590db
msg205858 - (view) Author: axil (axil) Date: 2013-12-10 21:00
This fix breaks the behavior of RotatingFileHandler.

Maxbytes>0 can now be only used with backupCount>0 otherwise it is ignored.

So all programs that are using Maxbytes>0 and backupCount=0 are now facing an infinitely growing logfile.
History
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60448
2013-12-10 21:00:39axilsetfiles: + test.py
versions: + Python 2.7
nosy: + axil

messages: + msg205858

type: behavior -> resource usage
2012-10-16 09:33:48python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg173020

resolution: fixed
stage: resolved
2012-10-16 06:57:53ned.deilysetnosy: + vinay.sajip
2012-10-16 06:15:52hyneksetnosy: + hynek
2012-10-16 05:05:37richardcreate