Skip to content

Commit

Permalink
Use LogRecord.getMessage to get OLTP body
Browse files Browse the repository at this point in the history
This improves compatibility with logging libraries that use
`logging.setLogRecordFactory()` or patching to customize the message
formatting of the created `LogRecord`s. It does this by using the
processed `LogRecord`'s `getMessage()` method to get the body text
instead of using `record.msg % record.args`.

Also adds "getMessage" to the list of reserved attributes so if the
customization is done by patching the `getMessage` function on the
`LogRecord` directly (instead of using a subclass), it's not
accidentally treated as an attribute.
  • Loading branch information
pR0Ps committed Oct 14, 2024
1 parent 6e89388 commit 00fd1f4
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ def force_flush(self, timeout_millis: int = 30000) -> bool:
"exc_text",
"filename",
"funcName",
"getMessage",
"message",
"levelname",
"levelno",
Expand Down Expand Up @@ -548,7 +549,7 @@ def _translate(self, record: logging.LogRecord) -> LogRecord:
body = self.format(record)
else:
if isinstance(record.msg, str) and record.args:
body = record.msg % record.args
body = record.getMessage()
else:
body = record.msg

Expand Down

0 comments on commit 00fd1f4

Please sign in to comment.