Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

logging should cache LogRecord.message #122089

Open
Labels
stdlibPython modules in the Lib dirtype-featureA feature request or enhancement
@SmartHypercube

Description

@SmartHypercube

Bug report

Bug description:

logging currently does not cacheLogRecord.message:

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

record.message=record.getMessage()

Sincelogging caches other string-formatting related results such asLogRecord.asctime andLogRecord.exc_text, I would like to suggest:

  1. LogRecord.getMessage should checkself.message first. If it is not computed yet, it should compute the message and set this attribute before returning.
  2. 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

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp