A C++ project that reads and analyzes structured log files to generate a detailed summary report.
The project demonstrates file handling, STL usage, object-oriented design, and data analysis in C++.
This Log File Analyzer processes a log file containing:
- timestamps
- log levels (INFO / WARN / ERROR)
- log messages
It extracts useful insights such as:
- log time range
- frequency of each log level
- most frequent messages
- timestamps of WARN and ERROR logs
- a final summarized report saved to a text file
-
logEntryclass- Represents a single log entry
- Stores:
- timestamp
- log level
- log message
-
logAnalyzerclass- Reads the log file
- Parses each line
- Maintains counters using STL containers
- Generates a well-structured summary report
- C++ (STL)
- File handling (
ifstream,ofstream) - Object-Oriented Programming
vector,map- String parsing
- Clean separation of responsibilities between classes
Each line in the log file must follow this exact structure:
YYYY-MM-DD HH:MM:SS→ Timestamp (19 characters)LEVEL→ Log level (INFO,WARN, orERROR)Message→ Description of the event (can contain spaces)
⚠️ Note:
- Timestamp must always be at the beginning of the line
- Log level and message must be separated by a single space
- Each log entry should be on a new line
The generated summary includes:
- Log time range (first to last timestamp)
- Count of each log level
- Count of each unique message
- Most frequent log level and message
- Timestamps where WARN and ERROR occurred
- Actionable warnings for repeated ERROR/WARN logs
- Clone the repository
- Place your
log.txtfile in the same directory - Compile the code:
g++ log_analyzer.cpp -o log_analyzer
./log_analyzer