Count Log Level Occurrences in Application Log File
Beginner Mode

Start your terminal to use beginner mode.

Scenario

An application log file needs to be analyzed to count occurrences of different log levels. You need to parse the log file and generate a summary of log level counts.

Task

Write a Python script at /home/interview/count_logs.py that reads /var/log/app.log, counts occurrences of each log level (DEBUG, INFO, WARN, ERROR) in a case-insensitive manner, and saves the counts as JSON to /home/interview/log_counts.json.

Example

Expected output format in /home/interview/log_counts.json:

{
  "DEBUG": 15,
  "INFO": 42,
  "WARN": 8,
  "ERROR": 3
}

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →