Skip to content

Add --top N to --summary - #4

Merged
Gulliby merged 1 commit into
mainfrom
feature/top-summary
Oct 13, 2026
Merged

Gulliby merged 1 commit into
mainfrom
feature/top-summary

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Before

--summary always listed the five most frequent error messages, so on a log with many distinct failures the rest were hidden, and on a short log five lines were more than needed.

After

--top N (or --top=N) sets the number of listed error messages, from 1 to 100. Without it nothing changes.

$ logslice errors.log --summary --top 2
Level counts:
DEBUG: 0
INFO: 0
WARNING: 0
ERROR: 3
CRITICAL: 1
Top 2 error messages:
  2  Disk full
  1  Timeout
Skipped lines: 0

It works with both --summary-format text and json. An invalid value exits with status 2 and an argparse message; --top without --summary exits with status 2 and logslice: --top requires --summary.

How

  • src/logslice/filters.py: parse_top accepts one to three ASCII digits from 1 through 100.
  • src/logslice/summary.py: render and render_json take top (default 5).
  • src/logslice/cli.py: the --top option and the check that it needs --summary.
  • README.md: options row and a Top N example.
  • Tests: new tests/test_top.py, plus small additions to tests/test_cli.py and tests/test_summary.py.

--top N sets how many of the most frequent ERROR and CRITICAL messages the summary lists (1 to 100, default 5).
@Gulliby
Gulliby merged commit 13d935f into main Oct 13, 2026
6 checks passed
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