You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🐛 Route analyse/ logging by environment instead of a stderr handler at import (#73)
## Summary
Fixes#72. The `analyse/` layer installed a `logging.StreamHandler` on
its own loggers at **import time**, so routine INFO progress (`Source
files loaded: N`, …) went to **stderr** unconditionally — reddened by
tox/CI even though the build succeeds (exit 0) — and importing the
package took the handler/level/stream choice away from consumers
(against the stdlib guidance for libraries).
This adds an environment-aware logging facade and routes the shared
`analyse/` layer through whichever frontend is active, modelled on
`sphinx_needs/logging.py`.
## What changed
- **`logger.py`** — new `get_logger(name)` facade over a swappable
backend:
- **default (plain library):** stdlib logging, *no handler installed* →
INFO dropped silently, WARNING+ to stderr via `logging.lastResort`.
- **CLI:** the existing rich logger → INFO to **stdout**, WARNING to
stderr, honouring `--verbose`/`--quiet`.
- **Sphinx:** `sphinx.util.logging` → progress at `VERBOSE`, warnings
carrying `type="codelinks"` + a `subtype` (suppressible via
`suppress_warnings`, on the Sphinx warning stream).
- **`analyse/{analyse,utils,projects,oneline_parser}.py`** — drop the
import-time handler; use `get_logger(__name__)`. `utils.py`'s git
warnings (previously `logging.warning()` on the **root** logger, which
triggers `basicConfig`) now go through the facade with subtypes.
`oneline_parser.py`'s dead logging block (no log calls) is removed.
- **Entry points** — the CLI `analyse` command gains `-v/--verbose` &
`-q/--quiet` and calls `configure_cli(...)`; the Sphinx `setup()` calls
`configure_sphinx()`.
## Behaviour
| Environment | INFO progress | WARNING |
|---|---|---|
| plain library (no configure) | dropped | stderr (`lastResort`) |
| CLI (default) | stdout | stderr |
| CLI `--quiet` | hidden | stderr |
| Sphinx (normal build) | hidden | Sphinx warning stream
(`codelinks.<subtype>`) |
| Sphinx `-v` | Sphinx status stream | Sphinx warning stream |
The accessible-pygments double-print noted in the issue disappears too,
since codelinks no longer emits INFO that propagates to the root logger.
`propagate` is left untouched (so consumers can still capture our logs).
## Testing
- New `tests/test_logger.py`: no handler installed at import (regression
guard for #72); default mode drops INFO / emits WARNING; CLI routes
INFO→stdout & WARNING→stderr with `--quiet` suppressing INFO; Sphinx
routes via `SphinxLoggerAdapter` with `type`/`subtype`.
- New CLI test in `tests/test_cmd.py` for the `analyse` progress /
`--quiet` gating.
- Full suite green (212 passed), `mypy --strict` clean, `ruff` clean on
changed files.
- Manual repro — real `sphinx-build` of `tests/data/sphinx`: the INFO
progress no longer appears on stderr (was flooded before, including the
doubled accessible-pygments lines); only genuine warnings remain.
0 commit comments