The Log Parser is a Python-based tool designed to analyze log files and generate a structured report in JSON format. It helps users extract meaningful insights from log data.
- Parse log files to extract entries.
- Generate a detailed report in JSON format.
- Easy-to-use and customizable.
- Python 3.8 or higher
- Clone the repository:
git clone https://github.com/beard91/log_parser.git
- Navigate to the project directory:
cd log_parser
- Place your log file in the
logdirectory and name itsample_log.log. - Run the script:
python main.py
- The generated report will be saved in the
reportdirectory (automatically generated) asreport.json.
The project includes a suite of tests to ensure the functionality of the log parser. Below is a description of the key test cases:
-
Valid Log Line Parsing:
- Tests the ability to parse a correctly formatted log line.
- Verifies that the timestamp, log level, and message are extracted correctly.
-
Invalid Log Level:
- Tests the behavior when a log line contains an invalid log level.
- Ensures that a
ValueErroris raised.
-
Invalid Timestamp:
- Tests the behavior when a log line contains an invalid timestamp format.
- Ensures that a
ValueErroris raised.
-
Log File Parsing with Mixed Content:
- Tests the parsing of a log file containing valid lines, invalid lines, and empty lines.
- Verifies that valid entries are processed and invalid entries are recorded.
-
File Not Found:
- Tests the behavior when the specified log file does not exist.
- Ensures that a
FileNotFoundErroris raised.
-
Permission Denied:
- Tests the behavior when the log file cannot be read due to permission issues.
- Ensures that a
PermissionErroris raised.
To run the tests, use the following command:
pytestlog_parser/
├── main.py
├── pyproject.toml
├── README.md
├── src/
│ ├── log_analyzer/
│ │ ├── models.py
│ │ ├── parser.py
│ │ └── reporter.py
├── tests/
└── log/
└── sample_log.log