Skip to content

fix(log): add CRITICAL, ALERT, EMERGENCY and DEBUG log level support#1844

Open
Donotavio wants to merge 1 commit into
rtk-ai:developfrom
Donotavio:fix/log-add-critical-alert-emergency
Open

fix(log): add CRITICAL, ALERT, EMERGENCY and DEBUG log level support#1844
Donotavio wants to merge 1 commit into
rtk-ai:developfrom
Donotavio:fix/log-add-critical-alert-emergency

Conversation

@Donotavio
Copy link
Copy Markdown

Problem

The log filter recognized only `ERROR`, `FATAL`, `PANIC`, `WARN`, and `INFO`. Lines with `CRITICAL`, `ALERT`, `EMERGENCY`, or `DEBUG` were silently discarded — not summarized, not flagged, gone.

Python's standard `logging` module defines `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` — the highest severity level, used by Django, FastAPI, Flask, and any stdlib-based framework. RTK was silently eliminating the most important level.

Real impact: An AI agent does incident triage, sees one `[ERROR]` (a transient retry), concludes minor issue, closes investigation. The `[CRITICAL]` line — "Payment service unreachable, 4821 transactions pending" — was never shown.

Fix

  • `CRITICAL`/`ALERT`/`EMERGENCY` → new highest-severity bucket shown in `[CRITICALS]` section before `[ERRORS]`
  • `DEBUG` → count-only (high-volume, no per-line detail block)
  • Summary lines now conditional (only shown when count > 0)

Quality improvements

Issue Fix
O(n×k) Vec+find() at render time HashMap<String,String> for O(1) lookup
byte-length truncation guard chars().count() for correct multi-byte handling
fs::read_to_string without context .with_context() added
3 near-identical render blocks render_entries() helper extracted
Inline truncation duplicates utils Reuses core::utils::truncate()
Non-deterministic HashMap order Secondary sort by key for stable snapshots

Tests

  • `test_critical_level_not_silently_discarded` — CRITICAL/ALERT/EMERGENCY appear in output
  • `test_log_critical_snapshot` — insta snapshot of full output format
  • `test_log_critical_token_savings` — ≥60% savings on 55-line fixture with repeated errors

Identified via adversarial testing: https://www.reddit.com/r/ClaudeCode/comments/1spiy8t/

The log filter recognized only ERROR/FATAL/PANIC/WARN/INFO. Python's
CRITICAL level (highest in the standard logging module, used by Django,
FastAPI, Flask) was silently discarded. An AI agent triaging incidents
via rtk log would never see CRITICAL events.

Changes:
- Add CRITICAL/ALERT/EMERGENCY bucket shown in [CRITICALS] section
  before [ERRORS], as these have higher severity than ERROR
- Add DEBUG count-only tracking (high-volume, no detail block needed)
- Replace O(n*k) Vec+find() lookup with O(1) HashMap<String,String>
- Extract render_entries() helper to eliminate 3 near-identical blocks
- Reuse core::utils::truncate() for correct multi-byte char handling
- Make summary lines conditional (only shown when count > 0)
- Add deterministic secondary sort to ensure stable snapshot output
- Add fixture (55 lines with repeated errors) and snapshot test
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 11, 2026

CLA assistant check
All committers have signed the CLA.

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.

2 participants