Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Log Parser in Python
00:00
5 left

Log Parser in Python

MediumPython

Problem

Write a log parser in Python.

Asked in the Technical Evaluation stage.

Implement parse_logs(lines). Each valid line has the format <timestamp> <level> <message>, where timestamp is an ISO-8601 UTC value ending in Z, and level is one of INFO, WARN, ERROR, or DEBUG. Return a dictionary containing valid parsed records in input order, counts by level, and the number of malformed lines. Ignore malformed lines rather than raising an exception.

Constraints

  • 1 <= len(lines) <= 1000
  • Each line contains at most 500 characters
  • A valid timestamp uses the form YYYY-MM-DDTHH:MM:SSZ
  • Valid levels are INFO, WARN, ERROR, and DEBUG
  • A valid message contains at least one character

Function Signature

def parse_logs(lines):
Interviewer

Your question is Log Parser in Python. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.