Command-line tool to analyze log files and summarize counts by level.
Project description
Quick Start
log-analyzer -f sample.log
log-analyzer -f sample.log --format csv
log-analyzer -f dated.log --date-summary
A small CLI tool that reads a log file, counts log levels, and outputs the counts in a chosen format.
CLI tool to count log levels (INFO/WARNING/ERROR/DEBUG) in a log file.
## Date Summary
Group logs by date and count levels per day:
```bash
log-analyzer -f dated.log --date-summary
Sort by date
log-analyzer -f dated.log --date-summary --sort date
Sort by total count
log-analyzer -f dated.log --date-summary --sort total
Reverse order
log-analyzer -f dated.log --date-summary --sort date --reverse
Mininmum total filter
``bash Show only dates with total logs >= N: log-analyzer -f dated.log --date-summary --min-total 2
#### Limit number of rows
```bash
log-analyzer -f dated.log --date-summary --limit 2
CSV output
log-analyzer -f dated.log --date-summary --format csv
JSON output
log-analyzer -f dated.log --date-summary --format json --indent 2
Example output
2026-03-01 ERROR: 1 (50.0%) WARNING: 0 (0.0%) INFO: 1 (50.0%) DEBUG: 0 (0.0%) TOTAL: 2
2026-04-01 ERROR: 0 (0.0%) WARNING: 0 (0.0%) INFO: 2 (66.7%) DEBUG: 1 (33.3%) TOTAL: 3
Date Filtering
Filter logs by date before counting or summarizing.
Since date
log-analyzer -f dated.log --since 2026-03-10
Until date
log-analyzer -f dated.log --until 2026-04-01
Since and until together
log-analyzer -f dated.log --since 2026-03-10 --until 2026-04-01
Today only
log-analyzer -f dated.log --today
Last N days
log-analyzer -f dated.log --last-days 7
Date filtering with date summary
log-analyzer -f dated.log --since 2026-03-10 --date-summary
Combined Usage Examples
Use multiple options together for more control.
Date range + summary + sort
log-analyzer -f dated.log --since 2026-03-01 --until 2026-04-01 --date-summary --sort total
Date summary + minimum total + limit
log-analyzer -f dated.log --date-summary --min-total 2 --limit 3
Date summary + reverse order
log-analyzer -f dated.log --date-summary --sort date --reverse
Date filtering + CSV output
log-analyzer -f dated.log --since 2026-03-01 --format csv
Date filtering + JSON output
log-analyzer -f dated.log --last-days 7 --format json --indent 2
Summary shortcut
log-analyzer -f dated.log --summary
Equivalent to:
log-analyzer -f dated.log --date-summary --sort total
Combine multiple options for more control.
log-analyzer -f dated.log --since 2026-03-01 --until 2026-04-01 --date-summary --min-total 2 --sort total --reverse --limit 5 --format json --indent 2
Install (editable / development)
From the project root:
pip install -e .
Show help: bash log-analyzer -h
Run with default settings
(uses data/sample.log, table format, sorted by level):
```bash
logan
Specify a log file:
logan -f data/sample.log
Output formats
Table (default):
logan -f data/sample.log --format table
Example output ERROR: 2 WARNING: 1 INFO: 3 DEBUG: 0
CSV:
logan -f data/sample.log --format csv
JSON:
logan -f data/sample.log --format json
Example output:
{
"ERROR": 2,
"WARNING": 1,
"INFO": 3,
"DEBUG": 0
}
Sorting
Sort by log level order (default):
```bash
logan -f data/sample.log --sort level
Sort by count (largest first):
logan -f data/sample.log --sort count
Reverse final order:
logan -f data/sample.log --sort count --reverse
Write Output to a file Write out put to a file instead of printing to the console:
logan -f data/sample.log format table --output out.txt
---
To overwrite an existing file:
```bash
logan -f data/sample.log --output out.csv --force
if the file is open(for example in Excel),the CLIwill return an error.
Filtering Specific Levels
you can limit output to specific log levels:
```bash
logan -f data/sample.log --level ERROR WARNING
Exit Codes
o - Success
2 - CLI erroe or file wrie failure
## Design notes
`run_logic(...)` is a pure function:
- no argparse
- no printing
- no sys.exit
- returns ordered counts
`main(...)` handles CLI parsing and error handling.
Printers only print data and do not sort.
---
## Tests
Run all tests:
```bash
python -m pytest
Final check
- CLI runs correctly
- All tests pass
- Editable install works (
pip install -e .)
Testing GitHub Actions workflow
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file log_analyzer_sattarab-0.40.0.tar.gz.
File metadata
- Download URL: log_analyzer_sattarab-0.40.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5b7fa0b2f4cf301ba58f2eb30b003fa984ea28801b2182381b3c36b0eb68608
|
|
| MD5 |
7c064e5a6726a0fe3b1745b00ec67645
|
|
| BLAKE2b-256 |
874d9b49748b78e5bf9c3cff5f439fbc96e93b9d34d4b692c1a6a1ef4fbc5d56
|
Provenance
The following attestation bundles were made for log_analyzer_sattarab-0.40.0.tar.gz:
Publisher:
python-package.yml on sattarab54/log-analyzer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
log_analyzer_sattarab-0.40.0.tar.gz -
Subject digest:
c5b7fa0b2f4cf301ba58f2eb30b003fa984ea28801b2182381b3c36b0eb68608 - Sigstore transparency entry: 1439133562
- Sigstore integration time:
-
Permalink:
sattarab54/log-analyzer@ae36d695b0395d33c8d642dacf54f0ceb16f5d87 -
Branch / Tag:
refs/tags/v0.40.0 - Owner: https://github.com/sattarab54
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@ae36d695b0395d33c8d642dacf54f0ceb16f5d87 -
Trigger Event:
release
-
Statement type:
File details
Details for the file log_analyzer_sattarab-0.40.0-py3-none-any.whl.
File metadata
- Download URL: log_analyzer_sattarab-0.40.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
333e201e27ecd5ac456ac378e3dee1bc399676bbfc81386854d3db01a0b2db5d
|
|
| MD5 |
3df42483d821700474b86d99c5dbb85e
|
|
| BLAKE2b-256 |
b6e9b70beb148470e832da395c5d7fc263aa2ab35db7a06ea00663afb63ee225
|
Provenance
The following attestation bundles were made for log_analyzer_sattarab-0.40.0-py3-none-any.whl:
Publisher:
python-package.yml on sattarab54/log-analyzer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
log_analyzer_sattarab-0.40.0-py3-none-any.whl -
Subject digest:
333e201e27ecd5ac456ac378e3dee1bc399676bbfc81386854d3db01a0b2db5d - Sigstore transparency entry: 1439133574
- Sigstore integration time:
-
Permalink:
sattarab54/log-analyzer@ae36d695b0395d33c8d642dacf54f0ceb16f5d87 -
Branch / Tag:
refs/tags/v0.40.0 - Owner: https://github.com/sattarab54
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@ae36d695b0395d33c8d642dacf54f0ceb16f5d87 -
Trigger Event:
release
-
Statement type: