Add leveled severity and structured context to log wrappers #260
Reference in New Issue
Block a user
Delete Branch "structured-leveled-logging"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #252.
Summary
bot_bottle/log.pywas bareprint(..., file=sys.stderr)wrappers with no levels or attributable context. This adds both, with zero behavior change at existing call sites.debug/info/warn/errornow carry an ordered severity, gated byBOT_BOTTLE_LOG_LEVEL(debug | info | warn | error, defaultinfo).debugis silent by default;erroralways surfaces (nothing sits above it), so the fataldiepath stays visible regardless of the configured level.contextmapping 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.contextand the default level, output is byte-identical to the originalbot-bottle: <msg>/bot-bottle: warning: <msg>/bot-bottle: error: <msg>lines. The 100+ existing single-string call sites are untouched; thecontextparameter is keyword-only with a default.cli/supervise.py, one of the two sites the issue names) to attacherror_typeandcrash_logcontext. 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 ownsupervise: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
tests/unit/test_log.py(13 cases): backward-compat output, context rendering + value quoting, level gating (debug silent by default,errorlevel suppresses info/warn, unknown level falls back,warningalias), anddiesurfacing at all levels.