Skip to content

[BUG] [alpha] cortex logs --clear --level ignores level filter and clears all log files #51573

@lucife-R-0014

Description

@lucife-R-0014

Project

cortex

Description

When users run cortex logs --clear --level <level>, the --level argument is not applied during clear operations. Instead of deleting only the selected level (for example error), the command removes every log file matching the age rule, which can unexpectedly wipe unrelated logs.

Root cause (this repo)

The command dispatch enters clear-mode early and executes run_clear() before level-based selection is considered. The clear path does not read self.level, so deletion proceeds without level filtering.

Fix direction (suggested)

  • Thread --level into run_clear() filtering logic.
  • If a level is provided, restrict deletion to matching filenames/categories only.
  • Emit explicit output showing which levels/files were targeted before deletion.

Code snapshot

  • src/cortex-cli/src/logs_cmd.rsrun() early return into run_clear()
  • src/cortex-cli/src/logs_cmd.rsrun_clear() deletion loop without level filter checks

Error Message

Cleared 3 log file(s) older than 0 days.

Debug Logs

System Information

Platform: Windows 11
Component: cortex-cli (release build)
Reproducible: Yes (consistent)

Screenshots / Media

https://github.com/ultrahighsuper/111/blob/main/2026-04-09_10h51_49.png

Steps to Reproduce

  1. Verify multiple log-level files exist (for example debug/error/info).
  2. Run cortex logs --clear --level error --keep-days 0.
  3. Observe the clear summary count.
  4. Run cortex logs --paths again.
  5. Confirm non-error files were also deleted.

Expected Behavior

--level error should clear only error-level log files and preserve other levels.

Actual Behavior

The clear operation removes all eligible log files regardless of level, effectively ignoring --level.

Additional Context

  • Impact includes unintended loss of logs users expected to keep.
  • Command output currently does not warn that the provided level filter was not honored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideIssues related to IDEvalidValid issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions