[issue9512] logging.handlers.RotatingFileHandler - mode argument not respected

Vinay Sajip report at bugs.python.org
Sun Aug 22 20:04:01 CEST 2010


Vinay Sajip <vinay_sajip at yahoo.co.uk> added the comment:

Sorry for the slow response, I've been on vacation.

The reason why the mode is set to "a" for rotating file handlers is as follows: the file is supposed to contain events from multiple runs of the program until rollover occurs. If a mode "w" (for example) is specified and respected, and you run the application twice, you would only get log output from the last run - not what you would intuitively expect. That's because in the second run, "w" would truncate an existing log file. With the mode set to "a", logs from multiple runs go into the same file, until rollover occurs - this seems to be the commonest use case.

Why do you need to specify "a+" rather than "a"? Do you need to read the log file concurrently with it being written, with the same file handle/descriptor?

The provided handlers are for text files, so non-text modes are not appropriate either. If you need support for binary files, you can create your own handler classes, perhaps based on the existing ones.

Marking as pending, awaiting feedback. Will close in a couple of weeks if none received.

----------
assignee: docs at python -> vinay.sajip
nosy:  -docs at python
status: open -> pending

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9512>
_______________________________________


More information about the Python-bugs-list mailing list