Desk Clarity

Everyday document & browser help

Python BasicConfig Appears Ignored: Inspect Existing Root Handlers

By ON Lab · Sources checked November 9, 2026

Inspect the root logger before changing configuration. Existing handlers can make a later basicConfig call ineffective; force=True replaces root handlers only when you deliberately own that configuration.

Reproduce the boundary in a disposable example

A later basicConfig call does not apply the expected level or format.

import io, logging
stream = io.StringIO()
logging.basicConfig(stream=stream, level=logging.WARNING,
                    format="OLD:%(message)s", force=True)
logging.basicConfig(level=logging.INFO, format="NEW:%(message)s")
logging.info("hidden")
logging.warning("visible")
assert stream.getvalue() == "OLD:visible\n"
assert len(logging.getLogger().handlers) == 1
logging.basicConfig(stream=stream, level=logging.INFO,
                    format="NEW:%(message)s", force=True)
logging.info("updated")
assert stream.getvalue().endswith("NEW:updated\n")
logging.shutdown()
print("existing handler boundary verified")

Read the result before changing application code

Run this in a fresh disposable process: it intentionally replaces global logging configuration. If the first INFO record is missing while the WARNING uses the old prefix, compare root handlers and the configuration order. A notebook, framework or earlier module-level logging call may already have configured a handler. Do not print credentials or full request objects as diagnostic records.

Choose the behavior your caller needs

Configure logging once at application startup when possible. In a hosted application, use the framework’s logging setup instead of forcing replacement. For missing named-logger records, inspect effective logger and handler levels separately. For duplicate records, inspect handler placement and propagation; this example addresses a configuration call being ignored, not every logging failure.

Scope and limits

force is available in Python 3.8 and later. This process-local example tests standard logging only; it does not inspect a particular hosting platform’s log collector.

Related: compare the adjacent data or execution boundary.

The embedded example was executed in an isolated local Python process on November 9, 2026. It is a reproducible boundary check, not a test of your full application.

Sources