plan(SP22): Task 3 review fix — get_logger returns BoundLoggerLazyProxy, not BoundLogger

The verbatim plan's test asserted isinstance(log, structlog.stdlib.BoundLogger),
but cache_logger_on_first_use=True makes get_logger return a lazy proxy on
first call. Test now uses duck-typing (hasattr('bind') + callable). Also
dropped the misleading caplog assertion and unused logging/structlog imports.
This commit is contained in:
Tyler
2026-06-21 13:26:59 -06:00
parent 6300280142
commit df10b55a34
@@ -501,16 +501,9 @@ def captured_stderr(monkeypatch):
buf.write(sys.stderr.getvalue() if hasattr(sys.stderr, "getvalue") else "") buf.write(sys.stderr.getvalue() if hasattr(sys.stderr, "getvalue") else "")
def test_setup_logging_emits_json(caplog): def test_setup_logging_emits_json():
"""After setup_logging, log records render as one JSON object per line """After setup_logging, log records render as one JSON object per line
with the keys cyclone uses (ts, level, logger, msg, extra).""" on stderr with the keys cyclone uses (event, level, timestamp, plus kwargs)."""
setup_logging(level="INFO")
log = get_logger("cyclone_pipeline.test")
log.info("hello", claim_id="CLM-1")
captured = caplog.text
assert "hello" in captured
# The structlog JSON renderer writes to stderr, not caplog by default.
# Use a direct capture:
import sys import sys
real = sys.stderr real = sys.stderr
sys.stderr = io.StringIO() sys.stderr = io.StringIO()
@@ -531,8 +524,10 @@ def test_setup_logging_emits_json(caplog):
def test_get_logger_returns_named_logger(): def test_get_logger_returns_named_logger():
log = get_logger("foo.bar") log = get_logger("foo.bar")
assert isinstance(log, structlog.stdlib.BoundLogger) # cache_logger_on_first_use=True returns a BoundLoggerLazyProxy on first
assert log.bind is not None # call; the contract is that .bind is callable, not the concrete class.
assert hasattr(log, "bind")
assert callable(log.bind)
``` ```
- [ ] **Step 2: Run test to verify it fails** - [ ] **Step 2: Run test to verify it fails**