From 7ba54dd3cc75c86283bdfe6949cb5b914dc98d02 Mon Sep 17 00:00:00 2001 From: Danut Ilisei Date: Fri, 18 Oct 2024 11:26:10 +0300 Subject: [PATCH] feat: remove most recent error from log message --- pantos/common/logging.py | 11 +---------- tests/test_logging.py | 3 +-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/pantos/common/logging.py b/pantos/common/logging.py index 1503a98..b0c5099 100644 --- a/pantos/common/logging.py +++ b/pantos/common/logging.py @@ -8,7 +8,6 @@ import logging.handlers import pathlib import sys -import traceback import typing import json_log_formatter # type: ignore @@ -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 diff --git a/tests/test_logging.py b/tests/test_logging.py index 042c5be..3a8c422 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -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', [