Skip to content

Commit

Permalink
feat: remove most recent error from log message
Browse files Browse the repository at this point in the history
  • Loading branch information
danut13 committed Oct 18, 2024
1 parent 1bd2457 commit 7ba54dd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
11 changes: 1 addition & 10 deletions pantos/common/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import logging.handlers
import pathlib
import sys
import traceback
import typing

import json_log_formatter # type: ignore
Expand Down Expand Up @@ -120,17 +119,9 @@ def json_record(self, message: str, extra: typing.Dict[str | int,
extra['levelname'] = record.levelname
if 'time' not in extra:
extra['time'] = datetime.datetime.utcnow()

extra['message'] = message
if record.exc_info:
exc_type = record.exc_info[0]
exc_value = record.exc_info[1]
human_readable_error = traceback.format_exception_only(
exc_type, exc_value)[-1].rstrip()
extra['message'] = f'{message} - {human_readable_error}'
extra['exc_info'] = self.formatException(record.exc_info)
else:
extra['message'] = message

return extra


Expand Down
3 changes: 1 addition & 2 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def test_datadog_custom_formatter_format_error_correct(
assert json_formatted_log[_LOG_EXTRA_KEY_2] == _LOG_EXTRA_VALUE_2
assert json_formatted_log[
_LOG_EXTRA_KEY_3] == _LOG_EXTRA_VALUE_3.name.capitalize()
assert json_formatted_log[
'message'] == f'{_LOG_MESSAGE} - ValueError: {_LOG_ERROR_MESSAGE}'
assert json_formatted_log['message'] == _LOG_MESSAGE


@pytest.mark.parametrize('logger', [
Expand Down

0 comments on commit 7ba54dd

Please sign in to comment.