Objective
Summarize a log file's levels and recurring errors without searching it by hand.
Three modules split parsing, analysis and reporting, with argparse in the entry point.
Challenges
- 01Extracting timestamp, level and multi-word message from each line
- 02Keeping the log format easy to change
How it was solved
- 01Pre-compiled regex with named capture groups, returned as a dict per line
- 02The whole format lives in one pattern in parser.py
Results
- No third-party dependencies: runs on the Python standard library
Overview
Runs from the terminal with the log path as its only argument (python main.py logs/sample.log) and prints the report to standard output.
Technical Implementation
Parsing
parser.py reads the file line by line and matches YYYY-MM-DD HH:MM:SS LEVEL message for INFO, WARNING and ERROR. Lines that don’t match are skipped; a missing file logs a warning and exits.
Analysis
analyzer.py counts entries per level with Counter and ranks ERROR messages with most_common(), top 5 by default.
Reporting
reporter.py prints aligned columns with f-string formatting.
Features
- Count of entries per log level
- Top 5 most frequent error messages with occurrence count
Technologies
- Python 3.10+
- Regex
- collections.Counter
- Argparse
