Skip to content

logs --session filter silently ignored: all log lines shown regardless of session #53395

@nightmare0329

Description

@nightmare0329

Bug Report

Version: cortex v0.0.7
Command: cortex logs --session <session-id>

Description

The --session flag for cortex logs is advertised in the help text as "Show logs from a specific session", but it has absolutely no effect — all log lines are shown regardless of the session filter.

Steps to Reproduce

Create a log file with entries from two different sessions:

[2024-01-01 10:00:00] session-abc INFO: Message from session-abc
[2024-01-01 10:01:00] session-xyz INFO: Message from session-xyz
[2024-01-01 10:02:00] session-abc DEBUG: Another from session-abc

Filter by one session:

$ cortex logs --session session-abc

Expected Behavior

Only lines containing session-abc should appear (2 lines).

Actual Behavior

All 3 lines are shown — session-xyz line included. Even filtering by a completely nonexistent session shows all lines:

$ cortex logs --session nonexistent-999
Log file: /home/user/.cache/cortex/logs/cortex-2024.log
------------------------------------------------------------
[2024-01-01 10:00:00] session-abc INFO: Message from session-abc
[2024-01-01 10:01:00] session-xyz INFO: Message from session-xyz
[2024-01-01 10:02:00] session-abc DEBUG: Another from session-abc

Screenshot (real binary output)

logs session filter bug

Root Cause

In src/cortex-cli/src/logs_cmd.rs, the session field is defined in the CLI struct but self.session is never read anywhere in the implementation. The run_show() and run_follow() functions only apply the level filter (self.level), and there is no equivalent code for session filtering.

The level filter works (lines 173-181):

let filtered_lines: Vec<&str> = if let Some(ref level) = self.level {
    let level_upper = level.to_uppercase();
    lines.iter().filter(|line| line.to_uppercase().contains(&level_upper)).copied().collect()
} else {
    lines
};

But there is no corresponding block for self.session.

File: src/cortex-cli/src/logs_cmd.rs, run_show() function (~line 167)

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions