classification
Title: Changing logging format for one handler changes it for all
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: hyamanieu, vinay.sajip
Priority: normal Keywords:

Created on 2021-07-11 17:12 by hyamanieu, last changed 2021-07-12 07:31 by hyamanieu. This issue is now closed.

Messages (3)
msg397258 - (view) Author: Amanieu (hyamanieu) Date: 2021-07-11 17:12
I want to stream a logger to several streams. Changing the standard format works, but changing the formatException function changes it for all!

As I am not entirely sure if it is a feature and I am misunderstanding something, I have posted on SO on this topic: https://stackoverflow.com/questions/68244691/changing-logging-format-for-one-handler-changes-it-for-all

It looks like an unexpected behavior to me when reading the doc.
msg397282 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2021-07-12 05:39
> It looks like an unexpected behavior to me when reading the doc.

Perhaps you missed this?

https://docs.python.org/3/library/logging.html?highlight=exc_text#logging.Formatter.format

"Note that the formatted exception information is cached in attribute exc_text. This is useful because the exception information can be pickled and sent across the wire, but you should be careful if you have more than one Formatter subclass which customizes the formatting of exception information. In this case, you will have to clear the cached value after a formatter has done its formatting, so that the next formatter to handle the event doesn’t use the cached value but recalculates it afresh."
msg397288 - (view) Author: Amanieu (hyamanieu) Date: 2021-07-12 07:31
Yes I did miss that. My bad and thank you so much.
History
Date User Action Args
2021-07-12 07:31:56hyamanieusetmessages: + msg397288
2021-07-12 05:39:28vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg397282

stage: resolved
2021-07-12 03:09:54xtreaksetnosy: + vinay.sajip
2021-07-11 17:12:20hyamanieucreate