Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Open
Description
Bug report
Bug description:
logging
currently does not cacheLogRecord.message
:
cpython/Lib/logging/__init__.py
Lines 391 to 401 in0dcbc83
defgetMessage(self): | |
""" | |
Return the message for this LogRecord. | |
Return the message for this LogRecord after merging any user-supplied | |
arguments with the message. | |
""" | |
msg=str(self.msg) | |
ifself.args: | |
msg=msg%self.args | |
returnmsg |
cpython/Lib/logging/__init__.py
Line 711 in0dcbc83
record.message=record.getMessage() |
Sincelogging
caches other string-formatting related results such asLogRecord.asctime
andLogRecord.exc_text
, I would like to suggest:
LogRecord.getMessage
should checkself.message
first. If it is not computed yet, it should compute the message and set this attribute before returning.Formatter
shouldn't setrecord.message
. It only needs to callLogRecord.getMessage
to get the message.
How to reproduce
importloggingclassA:def__repr__(self):print('repr called')return'<A>'logger=logging.getLogger()logger.addHandler(logging.StreamHandler())logger.addHandler(logging.StreamHandler())logger.error('%r',A())
Expected output
repr called<A><A>
Actual output
repr called<A>repr called<A>
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
No status