Author ecatmur2
Recipients ecatmur2
Date 2020-11-16.19:48:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
If a logging.FileHandler is configured with mode='w', or if logging.basicConfig is called with filemode='w' (as suggested by the Basic Logging Tutorial
and if some code logs during shutdown, after logging has closed its handlers (asyncio is prone to do this, e.g.),
then logging.FileHandler._open will reopen the log file with the same mode as it was originally opened with, potentially truncating it and losing valuable information:

import atexit
atexit.register(lambda:"so long"))
import logging
logging.basicConfig(filename='test.log', filemode='w', level=logging.INFO)"super important stuff")

$ python
$ cat test.log
INFO:root:so long

I have a hunch that the fix to issue 26789 will potentially make things worse, as previously at least there was a chance that logging had been fully unloaded so that the call to open would fail.
Date User Action Args
2020-11-16 19:48:23ecatmur2setrecipients: + ecatmur2
2020-11-16 19:48:22ecatmur2setmessageid: <>
2020-11-16 19:48:22ecatmur2linkissue42378 messages
2020-11-16 19:48:22ecatmur2create