Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Log Parsing Error Counter

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Python Log Parsing Error Counter. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Alten QA engineers review automated test output to identify failed or unstable executions. Given a list of log lines from an Alten QA run, count the entries whose severity level is ERROR.

Each valid line follows this format:

timestamp [LEVEL] message

The LEVEL value may be INFO, WARNING, ERROR, or another uppercase or lowercase severity. Count only lines whose parsed level equals ERROR, ignoring letter case. Ignore malformed lines that do not contain a complete bracketed level such as [ERROR].

Formal Specification

Implement count_error_messages(log_lines).

  • Input: log_lines, a list of strings.
  • Output: An integer representing the number of valid lines with severity ERROR.
  • The timestamp and message contents do not affect the result.

Constraints

  • 0 <= len(log_lines) <= 10^5
  • Each line contains at most 1,000 characters
  • Valid severity levels are enclosed in square brackets
  • Malformed lines must be ignored without raising an exception

Function Signature

def count_error_messages(log_lines):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output