Skip to content

About

Modular Python utility that analyzes log files, counts log levels, and extracts error messages.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📂 Python Log File Analyzer

A modular Python utility that analyzes log files, summarizes log levels, and extracts error and critical messages for easier debugging.


📌 Overview

Log files help developers understand application behavior and investigate failures. However, large logs can make it difficult to identify errors and warnings quickly.

Python Log File Analyzer processes a log file line by line, counts entries by log level, identifies empty lines, and displays error and critical messages with their original line numbers.

The application uses Python's pathlib to handle file paths and collections.Counter to maintain log-level statistics. Its modular structure separates analysis logic from user interaction.

✨ Features

  • Analyze log files line by line
  • Count INFO, WARNING, ERROR, CRITICAL, and DEBUG entries
  • Categorize unrecognized entries as OTHER
  • Count total, empty, and non-empty lines
  • Extract error and critical messages
  • Display line numbers for important entries
  • Validate file paths
  • Handle file-reading errors
  • Process files without loading the entire file into memory

🛠️ Tech Stack

  • Python 3
  • pathlib — filesystem path handling
  • collections.Counter — counting log levels
  • File handling, loops, functions, and exception handling

No third-party packages are required.

📁 Project Structure

python-log-file-analyzer/
├── main.py
├── log_analyzer.py
└── README.md
  • main.py handles user input and displays the analysis report.
  • log_analyzer.py contains the file-reading, log classification, counting, and error-extraction logic.

🚀 Getting Started

Prerequisites

Python 3.8 or newer.

Run the application

  1. Download or clone the repository.
  2. Open the project folder in your terminal.
  3. Run:
python main.py
  1. Enter the path to the log file you want to analyze.

💻 Example

Input file, sample.log:

2026-10-20 09:00:00 INFO Application started
2026-10-20 09:01:00 WARNING Disk space is low
2026-10-20 09:02:00 ERROR Database connection failed

2026-10-20 09:03:00 INFO Retry started
2026-10-20 09:04:00 CRITICAL Service unavailable

Expected summary:

Total lines: 6
Empty lines: 1
Non-empty lines: 5

INFO: 2
WARNING: 1
ERROR: 1
CRITICAL: 1
DEBUG: 0
OTHER: 0

The program also displays the line numbers and text of ERROR and CRITICAL entries.

🧠 Concepts Learned

  • Reading files line by line
  • Working with pathlib
  • Counting values with Counter
  • String processing and classification
  • Enumerating lines with line numbers
  • Handling empty lines
  • Separating logic into reusable modules
  • Handling file errors with exceptions

⚠️ Notes

  • Log classification uses keyword matching, so a word such as ERROR appearing in unrelated message text may affect its classification.
  • The analyzer does not modify the original log file.
  • Use log files you are authorized to access.

🔮 Future Improvements

  • Support configurable log formats
  • Filter logs by date and time
  • Export reports to CSV or JSON
  • Search for custom keywords
  • Generate visual summaries
  • Add automated unit tests

👨‍💻 Author

Ayushman Tiwari

GitHub: @ayushman-ece


Built with Python to practise file processing, log analysis, and modular programming.

About

Modular Python utility that analyzes log files, counts log levels, and extracts error messages.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages