Command-line tool to analyze log files and summarize counts by level.
Project description
log-analyzer
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.
Install (editable / development)
From the project root:
pip install -e .
Run
Show help:
logan -h
Run with default settings
(uses data/sample.log, table format, sorted by level):
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.34.0.tar.gz.
File metadata
- Download URL: log_analyzer_sattarab-0.34.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d11d646c1895510467302bf2f48b98ede98b40375156ed8fa1bb151234606e5
|
|
| MD5 |
96f02e71c617db4c8f0ce6918c6edffe
|
|
| BLAKE2b-256 |
814f9d5e48de76a444c3e63ae32c4d15eb0045de8d7ff9b339ed78c052f6b51b
|
Provenance
The following attestation bundles were made for log_analyzer_sattarab-0.34.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.34.0.tar.gz -
Subject digest:
7d11d646c1895510467302bf2f48b98ede98b40375156ed8fa1bb151234606e5 - Sigstore transparency entry: 1340763576
- Sigstore integration time:
-
Permalink:
sattarab54/log-analyzer@daf6e15f5e9c7c91c353adaee24fefb12f40b794 -
Branch / Tag:
refs/tags/v0.34.0 - Owner: https://github.com/sattarab54
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@daf6e15f5e9c7c91c353adaee24fefb12f40b794 -
Trigger Event:
release
-
Statement type:
File details
Details for the file log_analyzer_sattarab-0.34.0-py3-none-any.whl.
File metadata
- Download URL: log_analyzer_sattarab-0.34.0-py3-none-any.whl
- Upload date:
- Size: 11.4 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 |
52b253e76b0b7714ce3f3d805d2a8d49ad58fa78064c16972d10bb9e487debf1
|
|
| MD5 |
8a6cc7b528c333813b836b37b68f364c
|
|
| BLAKE2b-256 |
cb83479d12f0a6b00d990df4aa8ab62ba19ebc104b92155221e2f8b61d37f0d8
|
Provenance
The following attestation bundles were made for log_analyzer_sattarab-0.34.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.34.0-py3-none-any.whl -
Subject digest:
52b253e76b0b7714ce3f3d805d2a8d49ad58fa78064c16972d10bb9e487debf1 - Sigstore transparency entry: 1340763579
- Sigstore integration time:
-
Permalink:
sattarab54/log-analyzer@daf6e15f5e9c7c91c353adaee24fefb12f40b794 -
Branch / Tag:
refs/tags/v0.34.0 - Owner: https://github.com/sattarab54
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@daf6e15f5e9c7c91c353adaee24fefb12f40b794 -
Trigger Event:
release
-
Statement type: