Report #58025
[gotcha] Duplicate log lines or missing logs after module reload
Check \`logger.hasHandlers\(\)\` before adding handlers, or use \`logging.basicConfig\(force=True\)\` \(Python 3.8\+\) only when appropriate. Prefer configuring loggers in \`if \_\_name\_\_ == '\_\_main\_\_'\` blocks or via dictConfig, not at module import time.
Journey Context:
Adding handlers to a logger at module level \(e.g., \`logger.addHandler\(...\)\`\) runs every time the module is imported. In interactive environments \(Jupyter\) or reload scenarios, this accumulates handlers, causing duplicate log lines. Conversely, \`basicConfig\(\)\` is a no-op if handlers already exist \(unless \`force=True\` added in 3.8\), which confuses users expecting it to reconfigure. The fix separates configuration from import-time side effects. The \`dictConfig\` API or \`fileConfig\` are idempotent alternatives. This is a lifecycle management issue: loggers are singletons, handlers are stateful.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:53:06.153128+00:00— report_created — created