Skip to content
Open
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
10 changes: 5 additions & 5 deletions solnlib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def log_exception(
"""

msg = _get_exception_message(e, full_msg, msg_before, msg_after)
logger.log(log_level, f'exc_l="{exc_label}" {msg}')
logger.log(log_level, f'exc_l="{exc_label}" | {msg}')


def _get_exception_message(
Expand All @@ -367,7 +367,7 @@ def _get_exception_message(
else:
error = traceback.format_exception_only(exc_type, exc_value)

msg_start = msg_before if msg_before is not None else ""
msg_mid = "".join(error)
msg_end = msg_after if msg_after is not None else ""
return f"{msg_start}\n{msg_mid}\n{msg_end}"
msg_start = msg_before + " | " if msg_before is not None else ""
msg_mid = "".join(error).replace("\n", " ").rstrip()
msg_end = " | " + msg_after if msg_after is not None else ""
return f"{msg_start}{msg_mid}{msg_end}"
10 changes: 6 additions & 4 deletions tests/unit/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ def test_log_exceptions_full_msg():
json.loads(test_jsons)
except Exception as e:
log.log_exception(mock_logger, e, "test type1", msg_before=start_msg)
err_msg = traceback.format_exc().replace("\n", " ").rstrip()
mock_logger.log.assert_called_with(
logging.ERROR,
f'exc_l="test type1" {start_msg}\n{traceback.format_exc()}\n',
f'exc_l="test type1" | {start_msg} | {err_msg}',
)


Expand All @@ -312,8 +313,8 @@ def test_log_exceptions_partial_msg():
)
mock_logger.log.assert_called_with(
logging.ERROR,
'exc_l="test type" some msg before exception\njson.decoder.JSONDecodeError: Expecting property '
"name enclosed in double quotes: line 1 column 2 (char 1)\n\nsome msg after exception",
'exc_l="test type" | some msg before exception | json.decoder.JSONDecodeError: Expecting property '
"name enclosed in double quotes: line 1 column 2 (char 1) | some msg after exception",
)


Expand All @@ -337,8 +338,9 @@ class AddonComplexError(Exception):
except AddonComplexError as e:
fun = getattr(log, func)
fun(mock_logger, e)
err_msg = traceback.format_exc().replace("\n", " ").rstrip()
mock_logger.log.assert_called_with(
logging.ERROR, f"exc_l={result} \n{traceback.format_exc()}\n"
logging.ERROR, f"exc_l={result} | {err_msg}"
)


Expand Down
Loading