Skip to content

Commit f6cd651

Browse files
committed
PB-931 Fix the exception traceback handling in formatter
The exc_text wasn't added to the output message properly, which meant we couldn't map it with the logging config in django like this: error: stack_trace: exc_text
1 parent 2465f18 commit f6cd651

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

logging_utilities/formatters/json_formatter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,17 @@ def format(self, record):
343343
if self.add_always_extra:
344344
extra = self._get_extra_attrs(record)
345345

346-
message = self.formatMessage(record)
347-
348-
if self.add_always_extra:
349-
self._add_extra_to_message(extra, message)
350-
351346
if record.exc_info:
352347
# Cache the traceback text to avoid converting it multiple times
353348
# (it's constant anyway)
354349
if not record.exc_text:
355350
record.exc_text = self.formatException(record.exc_info)
351+
352+
message = self.formatMessage(record)
353+
354+
if self.add_always_extra:
355+
self._add_extra_to_message(extra, message)
356+
356357
if record.exc_text:
357358
message['exc_text'] = record.exc_text
358359

0 commit comments

Comments
 (0)