Skip to content

Commit

Permalink
PB-931 Fix the exc_text field handling in JSON formatter
Browse files Browse the repository at this point in the history
Adding the exc_text field to the record before formatting a message.
This allows for formatting the message through the django logging
facility
  • Loading branch information
schtibe committed Jan 16, 2025
1 parent 460eccf commit afb9ae6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions logging_utilities/formatters/json_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,17 @@ def format(self, record):
if self.add_always_extra:
extra = self._get_extra_attrs(record)

message = self.formatMessage(record)

if self.add_always_extra:
self._add_extra_to_message(extra, message)

if record.exc_info:
# Cache the traceback text to avoid converting it multiple times
# (it's constant anyway)
if not record.exc_text:
record.exc_text = self.formatException(record.exc_info)

message = self.formatMessage(record)

if self.add_always_extra:
self._add_extra_to_message(extra, message)

if record.exc_text:
message['exc_text'] = record.exc_text

Expand Down

0 comments on commit afb9ae6

Please sign in to comment.