Repository navigation
v1.0.6
structguru v1.0.6
A stdlib-bridge control release. The bridge and Django's config builder gain a disable_existing_loggers policy with dictConfig semantics — but reversible — every bridge option can now be configured from environment variables at an explicit call site, and the managed installer refuses to stack a second bridge instead of silently duplicating every record. No changes to correct existing usage; upgrade in place from any v1.0.x.
Features
-
disable_existing_loggersoninstall_stdlib_bridge().Truedisables named loggers that already exist at installation time,Falsere-enables them — the same policylogging.config.dictConfigapplies, except reversible:uninstall_stdlib_bridge()restores the states the bridge changed, unless application code changed them again in the meantime. The root logger, and loggers created after installation, are never touched.bridge = install_stdlib_bridge(level="INFO", disable_existing_loggers=True) # ... existing named loggers are silenced while the bridge runs ... uninstall_stdlib_bridge(bridge) # their previous states come back
When the option is omitted, the installer reads
STRUCTGURU_STDLIB_DISABLE_EXISTING_LOGGERS; when that is unset too, existing states are preserved. An explicit Python value always wins over the environment. -
install_stdlib_bridge_from_env()— configure every bridge option fromSTRUCTGURU_STDLIB_*variables at a controlled point in application startup. Importing structguru still never touches the root logger; only the explicit call reads the environment.Variable Default STRUCTGURU_STDLIB_LEVELLOG_LEVEL, thenINFOSTRUCTGURU_STDLIB_CLEAR_HANDLERStrueSTRUCTGURU_STDLIB_DISABLE_EXISTING_LOGGERSpreserve existing states STRUCTGURU_STDLIB_SUPPRESS_LOGGERSempty comma-separated list STRUCTGURU_STDLIB_SUPPRESS_LEVELWARNINGBooleans accept
1/0,true/false,yes/no, andon/off; an invalid value raisesValueErrorbefore any logging state is changed. -
Django's
build_logging_config()acceptsdisable_existing_loggers. When omitted it reads the same environment variable and falls back to the previous hard-codedFalse, so existing settings modules keep their behavior. -
A runnable example.
examples/stdlib_existing_loggers/main.pydemonstrates the policy from code and from the environment, and runs as part of the test suite so it cannot rot.
Changed
- Only one managed bridge can be active. A second
install_stdlib_bridge()call now raisesRuntimeErrorinstead of stacking a second handler that delivered every third-party record twice. A bridge whose handler was detached by hand is cleaned up — its logger-state snapshot restored — before a replacement installs.
Packaging & CI
- Cargo dependencies refreshed: fancy-regex 0.18 → 0.19, pyo3 0.29.2, plus compatible serde, serde_json, regex, and time updates.
- The internal
pathdependency is exempted from the cargo-deny wildcard ban, socargo denyenforces the ban for real dependencies without failing on the workspace-internal crate link.
Docs
- The README and the integrations guide document the existing-logger policy, the full environment-variable table, and the precedence rules (explicit value → environment → preserve).
Test coverage
- 40 new tests pin the policy semantics: preserve/disable/re-enable and restore-on-uninstall (including the "application changed it since" case), placeholder and root/later-logger exclusions, environment precedence and validation-before-mutation, duplicate-install rejection, and the example smoke paths — 451 Python tests and 66 Rust tests in total.