Add leveled severity and structured context to log wrappers #260

Merged
didericis merged 1 commits from structured-leveled-logging into main 2026-06-24 15:43:12 -04:00
Collaborator

Closes #252.

Summary

bot_bottle/log.py was bare print(..., file=sys.stderr) wrappers with no levels or attributable context. This adds both, with zero behavior change at existing call sites.

  • Levelsdebug / info / warn / error now carry an ordered severity, gated by BOT_BOTTLE_LOG_LEVEL (debug | info | warn | error, default info). debug is silent by default; error always surfaces (nothing sits above it), so the fatal die path stays visible regardless of the configured level.
  • Context — every wrapper takes an optional context mapping rendered as a parseable [k=v ...] suffix (keys sorted; whitespace/quoted values quoted), so failures can be filtered and correlated instead of being flat strings.
  • Backward compatible — with no context and the default level, output is byte-identical to the original bot-bottle: <msg> / bot-bottle: warning: <msg> / bot-bottle: error: <msg> lines. The 100+ existing single-string call sites are untouched; the context parameter is keyword-only with a default.
  • Demonstration — wires the supervise crash path (cli/supervise.py, one of the two sites the issue names) to attach error_type and crash_log context. The existing crash-logging test still passes because the context is appended after the unchanged message.

Scope / PRD

Treated as PRD-exempt per the conventions (contained, backward-compatible single-module enhancement). The other named site, supervise_server.py:519, writes directly to stderr with its own supervise: prefix rather than going through this module; converting the sidecar server's logging convention is out of scope here and can be a follow-up.

Tests

  • New tests/unit/test_log.py (13 cases): backward-compat output, context rendering + value quoting, level gating (debug silent by default, error level suppresses info/warn, unknown level falls back, warning alias), and die surfacing at all levels.
  • Full unit suite green (1085 passed); pyright-strict clean on changed files.
Closes #252. ## Summary `bot_bottle/log.py` was bare `print(..., file=sys.stderr)` wrappers with no levels or attributable context. This adds both, with **zero behavior change at existing call sites**. - **Levels** — `debug` / `info` / `warn` / `error` now carry an ordered severity, gated by `BOT_BOTTLE_LOG_LEVEL` (`debug | info | warn | error`, default `info`). `debug` is silent by default; `error` always surfaces (nothing sits above it), so the fatal `die` path stays visible regardless of the configured level. - **Context** — every wrapper takes an optional `context` mapping rendered as a parseable ` [k=v ...]` suffix (keys sorted; whitespace/quoted values quoted), so failures can be filtered and correlated instead of being flat strings. - **Backward compatible** — with no `context` and the default level, output is byte-identical to the original `bot-bottle: <msg>` / `bot-bottle: warning: <msg>` / `bot-bottle: error: <msg>` lines. The 100+ existing single-string call sites are untouched; the `context` parameter is keyword-only with a default. - **Demonstration** — wires the supervise crash path (`cli/supervise.py`, one of the two sites the issue names) to attach `error_type` and `crash_log` context. The existing crash-logging test still passes because the context is appended after the unchanged message. ## Scope / PRD Treated as **PRD-exempt** per the conventions (contained, backward-compatible single-module enhancement). The other named site, `supervise_server.py:519`, writes directly to stderr with its own `supervise:` prefix rather than going through this module; converting the sidecar server's logging convention is out of scope here and can be a follow-up. ## Tests - New `tests/unit/test_log.py` (13 cases): backward-compat output, context rendering + value quoting, level gating (debug silent by default, `error` level suppresses info/warn, unknown level falls back, `warning` alias), and `die` surfacing at all levels. - Full unit suite green (1085 passed); pyright-strict clean on changed files.
didericis-claude added 1 commit 2026-06-24 15:38:20 -04:00
feat(log): add leveled severity and structured context to log wrappers
test / unit (pull_request) Successful in 31s
test / integration (pull_request) Successful in 16s
lint / lint (push) Successful in 1m39s
test / unit (push) Successful in 31s
test / integration (push) Successful in 16s
Update Quality Badges / update-badges (push) Successful in 1m32s
7cb967770e
log.py was bare print-to-stderr wrappers with no levels or attributable
context (issue #252). Add:

- Ordered severities (debug/info/warn/error) gated by
  BOT_BOTTLE_LOG_LEVEL (default info). debug is silent by default;
  error always surfaces (nothing sits above it), so the fatal die path
  stays visible regardless of configured level.
- An optional `context` mapping on every wrapper, rendered as a
  parseable ` [k=v ...]` suffix (keys sorted; whitespace/quoted values
  quoted) so failures can be filtered and correlated.

Default output with no context is byte-identical to the original lines,
so the 100+ existing single-string call sites are unaffected. Wires the
supervise crash path (the example the issue names) to attach error_type
and crash_log context. Adds test_log.py (backward-compat, context
rendering, level gating, die surfacing).

Closes #252.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YcU7nerbg8cVj9R4EkpfLJ
didericis merged commit 7cb967770e into main 2026-06-24 15:43:12 -04:00
didericis deleted branch structured-leveled-logging 2026-06-24 15:43:13 -04:00
Sign in to join this conversation.