Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove most recent error from log message #51

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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