Find Error Patterns
Advanced · Write the code · from Build a Log File Parser That Finds Errors and Patterns
From the lesson: Step 4: Find Time-Based Patterns
Patterns in log data often reveal the root cause of problems. If errors cluster around the same time, it usually means a single event caused multiple failures. Let's analyze error timing to find these clusters.
Read this part of the lessonWrite a function find_error_bursts(log_text, window_minutes=5) that:
1. Parses all ERROR and CRITICAL entries with their timestamps
2. Groups errors that occur within window_minutes of each other into "bursts"
3. Returns a list of bursts, where each burst is a dict with:
- start_time: timestamp of the first error in the burst
- end_time: timestamp of the last error in the burst
- count: number of errors in the burst
- messages: list of error messages
Print each burst found. A burst is a group where each consecutive error is within the window of the previous one.
More Log Parser exercises
- Parse Log LinesAdvanced
- Count Log LevelsAdvanced
- Classify Errors by TypeAdvanced
- Generate Error SummaryAdvanced
- The Complete LogParser ClassAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz