feat(logs): --level filter on logs tail (RFC P3 first sub-task)#39
Draft
ulmentflam wants to merge 1 commit into
Draft
feat(logs): --level filter on logs tail (RFC P3 first sub-task)#39ulmentflam wants to merge 1 commit into
ulmentflam wants to merge 1 commit into
Conversation
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
513f4e3 to
0120b0a
Compare
4 tasks
Closes the `logs tail` / level-filter checkbox of RFC
`rfc-developer-ux-verbs` (P3). `logs path` / `logs tail` /
`logs clear` already existed at `corpus_forge/diagnostics/logs.py`
from Phase L Wave 6; only the `--level` filter was missing.
Change
------
`corpus_forge/diagnostics/logs.py`:
- New `_LEVEL_RANK` constant mirroring stdlib logging numeric
levels (DEBUG=10 / INFO=20 / WARN=WARNING=30 / ERROR=40 /
CRITICAL=50).
- New `_passes_level_filter(line, min_level)` helper applying the
filter against `_LOG_LINE_RE`. Documented contract:
- `min_level is None` → everything passes.
- Parseable line + level rank ≥ min_level → passes.
- Parseable line + level rank < min_level → dropped.
- Unparseable line (no level token) + min_level set → dropped.
User who asks for `--level error` does not want tracebacks
and `print()` output; they're not at any meaningful level.
- New `_resolve_level_arg(level)` helper that maps the user's CLI
string to a stdlib rank, or raises `typer.BadParameter` (clean
CLI error, naming the bad token + listing the accepted set).
- `logs_tail_cmd` now takes `--level <name>` and threads `min_level`
through both the one-shot path and `_tail_follow(..., min_level=)`.
- `_tail_follow` accepts an optional `min_level` and applies the
filter to both the initial tail and the streaming poll.
Tests
-----
8 new tests in `tests/diagnostics/test_logs_subcommand.py` under
`TestLogsTailLevelFilter`:
- No `--level` arg → everything prints (regression pin).
- `--level warn` drops debug + info.
- `--level error` drops warning + below.
- Filter is case-insensitive.
- `warn` and `warning` aliases both work.
- Unknown level token → exit ≠ 0 with `Invalid value` + accepted set
shown.
- `--level error` drops the unparseable lines from a traceback.
- `_passes_level_filter` exposed for non-CLI callers.
Verified
--------
- `uv run pytest tests/diagnostics/test_logs_subcommand.py -v` →
17/17 in 0.42s (8 new + 9 pre-existing).
- `uv run ruff check`, `uv run ruff format --check`,
`uv run pyrefly check corpus_forge/diagnostics/logs.py` → clean.
The pre-existing `Lint + format + typecheck` CI failure on `main`
(PR #31 fixes) will still fail this PR's lint job until #31 lands
and this rebases. Same blast pattern as the earlier nightly PRs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0120b0a to
432ab00
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
logs tail/ level-filter checkbox of RFCrfc-developer-ux-verbs(P3). Thelogs path/tail/cleartrio already existed from Phase L Wave 6; only the--level <name>filter was missing.--level debug|info|warn|warning|error|critical(case-insensitive). Lines below the named severity are dropped in both single-shot and--followmodes.print()) are dropped when a level filter is active — the user who asks for--level errordoesn't want unstructured noise mixed in.typer.BadParameterwith the bad token named + accepted set listed (no silent no-op).tests/diagnostics/test_logs_subcommand.py.Independent of every other open RFC PR. The location note in the RFC tick: the existing
logsverbs live atcorpus_forge/diagnostics/logs.py(not the RFC'sadmin/logs.pypath); kept them there since the rest of the trio is already there.Test plan
uv run pytest tests/diagnostics/test_logs_subcommand.py -v→ 17/17 in 0.42s (8 new + 9 pre-existing).uv run ruff check,uv run ruff format --check,uv run pyrefly check corpus_forge/diagnostics/logs.py→ all clean (0 errors).Testsmatrix green.Lint + format + typecheckgreen — blocked on PR chore(tests): drop useless return None in _MissingFinder.find_spec (ruff PLR1711) #31 + rebase (same pre-existing main breakage as the other open PRs).🤖 Generated with Claude Code