Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

log_analyzer_sattarab-0.12.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

log_analyzer_sattarab-0.12.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file log_analyzer_sattarab-0.12.0.tar.gz.

File metadata

  • Download URL: log_analyzer_sattarab-0.12.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for log_analyzer_sattarab-0.12.0.tar.gz
Algorithm Hash digest
SHA256 9838b7d3a1c9bee9a3143a8a06f024d885bb2e5af03246026b52a4999e9150b3
MD5 38d127fe65dff552b09b5011d1f9ff24
BLAKE2b-256 492d42bf7aad7b87b37b54e19d0dc04ed511f63903345b14e5f59f2c7c67a58b

See more details on using hashes here.

Provenance

The following attestation bundles were made for log_analyzer_sattarab-0.12.0.tar.gz:

Publisher: python-package.yml on sattarab54/log-analyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file log_analyzer_sattarab-0.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for log_analyzer_sattarab-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cebef3da044aa36089d5ca3a4e60c71def0058a4527b6ee3673a8535712184e9
MD5 e23e85da7bec70dbbf190c7b4d8c043b
BLAKE2b-256 ecd41a6f69cbc2a1e1bd740ad683fd0ce5dca7f2b7d9dc650bca1f1607b5d66e

See more details on using hashes here.

Provenance

The following attestation bundles were made for log_analyzer_sattarab-0.12.0-py3-none-any.whl:

Publisher: python-package.yml on sattarab54/log-analyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page