NS-029
documentedfiltered-not-absent
Python discards records below WARNING when no logging is configured
- reads as
- A script instrumented with logger.info() at every step produces no output at all. Conclusion drawn: the code path never ran.
- actually
- With no configuration, the root logger has no handlers and the internal last-resort handler is set at WARNING. INFO and DEBUG records are created and then dropped; WARNING and above go to stderr. The code ran, and said so, into nothing.
- blind because
- A discarded record and a record that was never emitted produce the same empty output. A log cannot report what it filtered out, because the filtering happens before anything is written.
- the check
- `logging.getLogger(__name__).isEnabledFor(logging.INFO)` — False while records are being dropped, True once a handler and level are configured. Observed on 3.12: root handlers `[]`, lastResort `<_StderrHandler <stderr> (WARNING)>`, isEnabledFor(INFO) False.
- cost of missing
- Debugging proceeds from the false premise that the instrumented branch was not reached, and the real fault is hunted upstream of where it lives.
- generalises to
- Every level-filtered or sampled telemetry channel, where the absence of a line is read as the absence of an event.
- source
- docs.python.org