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: RotatingFileHandler does not support any mode other than 'a'.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: elgovatos, vinay.sajip
Priority: normal Keywords:

Created on 2020-03-11 18:54 by elgovatos, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg363957 - (view) Author: Eric Govatos (elgovatos) Date: 2020-03-11 18:54
The RotatingFileHandler class located within lib/logging/handlers.py  does not accept any other 'mode' value than its default value of 'a' - even when the parameter is supplied, such as 'ab', to append bytes, this is disregarded and the mode is set back to 'a' if the maxBytes variable is greater than 0. 

While the reasoning behind this does make sense as the rotating file handler should only be appending data to files, this means that supplying a mode to append bytes is not supported. You can currently get around this by supplying the mode after constructing the handler.

Proposed solution would be to remove lines 146 and 147 from the class entirely and let the user decide on the file mode themselves.
msg364016 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-03-12 12:48
> supplying a mode to append bytes is not supported

That is correct, log files supported by standard library handlers are text files using some supported encoding. If you need to store arbitrary bytes directly in a log file, feel free to write your own handlers to do it.
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84119
2020-03-12 12:48:09vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg364016

stage: resolved
2020-03-11 19:07:06xtreaksetnosy: + vinay.sajip
2020-03-11 18:56:07elgovatossettitle: RotatingFileHandler does not support any other mode than 'a'. -> RotatingFileHandler does not support any mode other than 'a'.
2020-03-11 18:54:14elgovatoscreate