Merge branch 'logging-groups' into 'v3'
Add invocation ID to log message if available See merge request openflexure/openflexure-microscope-server!647
This commit is contained in:
commit
08f91854a9
2 changed files with 60 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue