logwarden v0.11.0¶
Status: Released 2026-11-23 · tag v0.11.0
Outcome: you know which log calls your tests never run. logwarden checks the log lines
that tests write. A log call that no test reaches is never checked, and those are mostly the
calls that matter: errors and exceptions. A prototype on four ai-suite services (2026-11-23)
found that tests run 27% to 50% of the log calls, and almost none on error paths: one service's
tests run none of its 16 error and 4 exception calls, while its line coverage is 64%.
logwarden log-coverage reports, per file and level, which log calls the tests run, from the
coverage data a test run already produces.
What's new¶
logwarden log-coverage --coverage FILE [PATHS...](Python source). It finds the log calls in the source (log.info(...),logger.warning(...),self.log.error(...),logging.exception(...),structlog.get_logger().bind(...).info(...),logger.log(logging.ERROR, ...)), and counts a call as reached when the coverage data says the statement that contains it ran.- Coverage data: coverage.py's
.coveragefile,coverage json, or Cobertura XML (coverage xml,pytest --cov-report=xml). Read without extra dependencies. - A log call is
<receiver>.<level>(...), with leveldebug,info,warning,warn,error,exception,critical,fatal,msgorlog, and a receiver whose text haslog,logger,logging,structlogorslogas a word (log,self._logger,app.logger, notdialogorcatalog).--receiver REGEXreplaces that rule. - Not counted: files under
tests/,test_*.py,conftest.py,.venv,venv,node_modules,build,dist,migrations; lines coverage.py excludes (# pragma: no cover).--exclude GLOBadds more. A source file missing from the coverage data counts as not reached. - Emitted, not just reached:
--logs FILE(the lines captured from the tests, e.g. withLOGWARDEN_CAPTURE) also counts the calls that wrote a log line, bycode.file.pathandcode.line.number. A call can run and write nothing (adebugcall below the log level).--logsalone, without--coverage, reports emitted calls only. - Output: a summary (reached / total, overall and per level), the files with the most
unreached calls, and the unreached calls as
path:line level receiver;--jsonfor the full result;--markdown FILEfor a job summary or PR comment. - A CI gate, off by default:
--fail-under PCTexits 1 when fewer than PCT% of the counted calls are reached (or emitted, with--logs).--levels error,exception,criticalcounts only those levels, e.g. "every error path is tested":logwarden log-coverage --coverage .coverage --levels error,exception,critical --fail-under 80 src/.
Changes you might notice¶
- A new command. Nothing else changes:
checkand its findings,--jsonkeys, exit codes.
Breaking changes¶
None.
Later¶
- Node, Go and Java source (the recipes): needs a parser per language.
- Unreached log calls in the Action's PR comment, as SARIF notes, and in the GitLab template.
Verification¶
| # | Claim | How it will be checked | Result |
|---|---|---|---|
| 1 | Finds the log calls | Unit fixtures: every receiver form above is found with its level (logger.log(logging.ERROR, ...) as error); warnings.warn, print, dialog.info(), catalog.error(), self.info() are not; a call inside a multi-line statement maps to that statement. On four ai-suite services: the found calls equal a grep for .<level>( minus the non-logger matches, each listed |
✅ tests/test_log_coverage.py::test_claim1_finds_the_log_calls: in the fixture (tests/data/logcov/) exactly the 10 marked calls are found, with log.log(logging.WARNING, ...) as warning, log.exception as exception, logging.error as error; the call inside result = compute(...) maps to the statement's first line; the call under # pragma: no cover is skipped (excluded_by_pragma 1); dialog.info, catalog.error, warnings.warn, obj.info, print are not found. test_claim1_receivers: 15 receivers (9 found, 6 not, incl. blog, logs_dir, self). Four ai-suite services: 44, 55, 35 and 20 calls found; a grep for .<level>( finds the same lines plus one, warnings.warn( (not a log call); nothing found that grep doesn't |
| 2 | Three coverage formats | One fixture project, its tests run under coverage.py: .coverage, coverage json and coverage xml give the same reached calls; a # pragma: no cover log call isn't counted; a file never imported counts as not reached |
✅ test_claim2_three_formats_agree: the fixture run under coverage.py; .coverage, coverage json and coverage xml give identical results (7 of 10 reached: the 7 marked as reached; app/unused.py, never imported, not reached; the pragma call not counted). test_claim2_paths_recorded_elsewhere: the JSON with every path moved under /builds/team/proj/ gives the same 7 |
| 3 | Emitted | The fixture's tests with LOGWARDEN_CAPTURE: --logs marks the calls that wrote a line; a debug call below the log level is reached but not emitted; --logs alone works |
✅ test_claim3_emitted: with the lines the fixture wrote (configure(), LOGWARDEN_CALLSITE=1): 7 reached, 6 wrote a line; the one reached but silent is the marked log.debug (level INFO). --logs alone: 6 emitted, reached and unreached are null |
| 4 | Real services | four ai-suite services: the same numbers as the prototype (one with all its tests passing: 20/55); --markdown and --json agree with the text |
✅ The command on the same coverage data as the prototype, four ai-suite services: 12/44, 20/55, 17/35, 10/20, identical to the prototype, from coverage json and from .coverage. test_claim4_outputs_agree: text, --json and --markdown give the same counts (7 of 10, 70%) and list the same 3 unreached calls; calls equals the sum over levels and over files |
| 5 | Gate | --fail-under exits 1 below and 0 at or above the threshold; --levels limits the count; usage errors (no coverage and no logs, unreadable file, unknown level) exit 2 |
✅ test_claim5_gate_and_levels: no gate: exit 0; --fail-under 70: 0, 71: 1 with "FAIL: 70% reached, required 71%"; --levels error,exception,critical: 4 calls, 2 reached, --fail-under 50: 0, 51: 1. test_claim5_usage_errors: no data, a missing coverage file, a file that isn't coverage data, an unknown level, a bad --receiver, a missing log file: exit 2 with the reason. uv run pytest: 350 passed |
| 6 | Docs, CI, release | docs/log-coverage.md (new page), docs/integration.md, STABILITY.md (command, --json keys), AGENTS.md, docs/roadmap.md (M9), CLI help; CI on Linux, macOS, Windows; dry run to TestPyPI; after the tag, PyPI and the image |
✅ docs/log-coverage.md (new page, in the site navigation), docs/integration.md (section in "Check in CI"), STABILITY.md (log-coverage --json keys), AGENTS.md (logcoverage.py), docs/roadmap.md (M9; the metrics milestones renumbered to v0.12.0 and v0.13.0), CLI help; strict site build passes. PR #20 CI (Linux, macOS, Windows, Python 3.10, coverage, speed, recipes, Docker) passed; main CI 45242112401 after the version bump passed. Dry run and after the tag: see below |
Post-release checks¶
- ✅ Dry run 45242113816 (before the tag): TestPyPI
0.11.0.dev25, image:0.11.0.dev25. Main CI 45242112401 passed. - ✅ Release run 45244715260 published PyPI
logwarden 0.11.0, imageghcr.io/ingeniator/logwarden:0.11.0and the GitHub release. - ✅
uvx logwarden==0.11.0 log-coverage --coverage coverage.jsonfrom PyPI on one of the trial services: 20 of 55 log calls reached, per level as in claim 4. - ✅ The image
:0.11.0from GHCR,--network none, uid 12345, the service mounted at/workand the coverage data (recorded with the host's absolute paths) mounted separately: the same 20 of 55, matched by trailing path.