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: logging.handlers.RotatingFileHandler - inconsistent mode
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: vinay.sajip, walkerh
Priority: normal Keywords:

Created on 2006-09-06 16:03 by walkerh, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg29778 - (view) Author: Walker Hale (walkerh) * Date: 2006-09-06 16:03
RotatingFileHandler does not remember the mode used to
open files. By default it will initially open its file
with 'a', but client code may set this to something
else. After rollover, the mode for the new file changes
to 'w'. The behavior is inconsistent with the interface.

At the very least the docstring for __init__ should
change to show that the mode parameter is not respected
after rollover.

This affects previous versions.
msg29779 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2006-09-11 22:31
Logged In: YES 
user_id=308438

I don't feel that the current behaviour is inconsistent,
because you normally want the current log file to be
appended to, when the program starts. (Of course, you can
override this to specify "w" and start with a new file for
every run.) However, when you rollover, you want the new
file to be truncated, and not have new log messages appended
to existing data. Hence, "a" is used at first, and "w" at
rollover. Remember, the log file before rollover (e.g.
test.log) is renamed to test.log.n, and rolled-over output
goes into test.log. Since the original test.log is now
test.log.n, what does it mean to open test.log with "a"?
Since test.log does not exist, opening with "w" and "a" are
equivalent.

If you spot a flaw in this reasoning, please re-open and
give a more detailed scenario which explains exactly why the
current behaviour is causing you a problem. In particular,
it would help if you could walk me through a scenario which
shows how the system would behave observably differently if
"a" were used instead of "w" at rollover.
History
Date User Action Args
2022-04-11 14:56:20adminsetgithub: 43951
2006-09-06 16:03:48walkerhcreate