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

GH-122089: Cache LogRecord.getMessage() the first time the message is formatted#134367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
pR0Ps wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
frompR0Ps:feature/logging-cache-message
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletionsLib/logging/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -303,6 +303,7 @@ def __init__(self, name, level, pathname, lineno,
ct = time.time_ns()
self.name = name
self.msg = msg
self.message = None
#
# The following statement allows passing of a dictionary as a sole
# argument, so that you can do something like
Expand DownExpand Up@@ -395,10 +396,13 @@ def getMessage(self):
Return the message for this LogRecord after merging any user-supplied
arguments with the message.
"""
msg = str(self.msg)
if self.args:
msg = msg % self.args
return msg
if self.message is None:
msg = str(self.msg)
if self.args:
msg = msg % self.args
self.message = msg

return self.message

#
# Determine which class to use when instantiating log records.
Expand DownExpand Up@@ -708,6 +712,8 @@ def format(self, record):
called to format the event time. If there is exception information,
it is formatted using formatException() and appended to the message.
"""
# note: LogRecord.getMessage() will set record.message already but
# custom LogRecord objects may not so it's assigned here anyway
record.message = record.getMessage()
if self.usesTime():
record.asctime = self.formatTime(record, self.datefmt)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Cache LogRecord.getMessage() the first time the message is formatted. Patch
by Carey Metcalfe.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp