Only format file log, add tests

This commit is contained in:
Joe Knapper 2026-07-07 14:47:53 +01:00
parent e42aaf2547
commit 013341272e
2 changed files with 56 additions and 15 deletions

View file

@ -234,3 +234,48 @@ def test_configure_logging_debug_mode(debug_flag, expected_level):
# Cleanup: Remove the OFM_HANDLER from the root logger so it doesn't
# interfere with other tests in the suite.
root_logger.removeHandler(ofm_logging.OFM_HANDLER)
def test_log_file_formatter_includes_invocation_id():
"""Check that invocation IDs are included in logs when available."""
formatter = ofm_logging.OFMLogFileFormatter(
"[%(levelname)s]%(invocation_id_str)s %(message)s"
)
record = logging.LogRecord(
name="test",
level=logging.INFO,
pathname="",
lineno=0,
msg="Test message",
args=(),
exc_info=None,
)
record.invocation_id = "abc123"
formatted = formatter.format(record)
assert "[invocation:abc123]" in formatted
assert "Test message" in formatted
def test_log_file_formatter_without_invocation_id():
"""Check that logs without invocation IDs still format correctly."""
formatter = ofm_logging.OFMLogFileFormatter(
"[%(levelname)s]%(invocation_id_str)s %(message)s"
)
record = logging.LogRecord(
name="test",
level=logging.INFO,
pathname="",
lineno=0,
msg="Test message",
args=(),
exc_info=None,
)
formatted = formatter.format(record)
assert "[invocation:" not in formatted
assert "Test message" in formatted