Parse and Summarise Log Files

easy
Unit 7 · Datetime I0/3 to milestone

When something breaks in production, you're often grepping logs. Write a parser that summarises them.

Each well-formed line looks like:

2024-05-01 10:00:01 ERROR [db] connection refused

That's a date, a time, a level (DEBUG, INFO, WARNING or ERROR), a service name in square brackets (letters, digits, _, . or -), then the message.

Implement parse_logs(lines) returning a dict:

  • "levels": count of lines per level (only levels that appear)
  • "errors_by_service": count of ERROR lines per service
  • "error_messages": ERROR messages in order
  • "skipped": number of lines that don't match the format, including blank lines

Lines may end with "\n".

#regex#strings#collections2 visible + 3 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Parse and Summarise Log Files · TechGradify