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 linesLines may end with "\n".