Skip to content

feat(logs): --level filter on logs tail (RFC P3 first sub-task)#39

Draft
ulmentflam wants to merge 1 commit into
mainfrom
nightly/logs-tail-level-20260522T130321Z
Draft

feat(logs): --level filter on logs tail (RFC P3 first sub-task)#39
ulmentflam wants to merge 1 commit into
mainfrom
nightly/logs-tail-level-20260522T130321Z

Conversation

@ulmentflam
Copy link
Copy Markdown
Owner

Summary

  • Closes the logs tail / level-filter checkbox of RFC rfc-developer-ux-verbs (P3). The logs path / tail / clear trio 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 --follow modes.
  • Unparseable lines (tracebacks, print()) are dropped when a level filter is active — the user who asks for --level error doesn't want unstructured noise mixed in.
  • Unknown level tokens produce a clean typer.BadParameter with the bad token named + accepted set listed (no silent no-op).
  • 8 new tests in tests/diagnostics/test_logs_subcommand.py.

Independent of every other open RFC PR. The location note in the RFC tick: the existing logs verbs live at corpus_forge/diagnostics/logs.py (not the RFC's admin/logs.py path); 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).
  • CI Tests matrix green.
  • CI Lint + format + typecheck green — 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 88744086-323e-4c11-b4e7-72f92ae78880

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nightly/logs-tail-level-20260522T130321Z

Comment @coderabbitai help to get the list of available commands and usage tips.

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>
@ulmentflam ulmentflam force-pushed the nightly/logs-tail-level-20260522T130321Z branch from 0120b0a to 432ab00 Compare May 25, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant