Report #46013
[gotcha] Logging output appears twice after configuring basicConfig
Clear existing handlers before reconfiguring: \`logging.getLogger\(\).handlers.clear\(\)\` before \`basicConfig\(\)\`, or guard all module-level code against premature logging calls that trigger implicit handler creation.
Journey Context:
When \`logging.info\(\)\` \(or similar\) is called before \`basicConfig\(\)\`, CPython automatically creates a default \`StreamHandler\` pointing to stderr to ensure something captures the output. Later, when you call \`basicConfig\(\)\` to set up file logging, it checks if the root logger has handlers—if it does \(because of that auto-created one\), it does NOT add new handlers or remove the old one. The root logger now has both the old stderr handler and your new file handler, producing duplicate output. The fix is either to clear handlers first, or to ensure no logging happens before configuration \(e.g., by configuring logging at the very top of the entry point before importing other modules that might log\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:42:35.238238+00:00— report_created — created