EasyParsingPython 3
Log Error Parser
Summarize top error messages from noisy logs with deterministic tie-breaking.
20m1 sample tests1 hidden tests
Log Error Parser
Implement top_errors(log_text, limit=3) for application logs.
Requirements
- Input is one string containing newline-separated log lines.
- Count only lines that contain
" ERROR ". - The error key is the message after
" ERROR ". - Ignore indented continuation lines for counting.
- Return a list of
(message, count)pairs. - Sort by count descending, then message ascending.
- Return at most
limitrows.
Example
python
1log_text = '''
22026-01-01 INFO start
32026-01-01 ERROR timeout
42026-01-01 ERROR bad gateway
52026-01-01 ERROR timeout
6'''
7
8assert top_errors(log_text, limit=2) == [("timeout", 2), ("bad gateway", 1)]Constraints
- Use standard-library Python only.
- Prefer
splitlines,Counter, or an explicit state machine.
Editor
1 2
Sample Tests
counts errors and sorts ties
from solution import top_errors
log_text = """
2026-01-01 INFO start
2026-01-01 ERROR timeout
2026-01-01 ERROR bad gateway
2026-01-01 ERROR timeout
2026-01-01 ERROR auth failed
2026-01-01 INFO done
"""
assert top_errors(log_text, limit=2) == [("timeout", 2), ("auth failed", 1)]Results
Run sample tests or submit all tests.