Projects · 5 / 19 Exercise Medium

Log analyzer

Objective

Create a Python program that analyses an application log using regular expressions and counters, and shows a summary.

Instructions

  • Read an integer n and then n lines. A valid line has the format YYYY-MM-DD HH:MM:SS LEVEL message, with level DEBUG, INFO, WARNING or ERROR. The message may contain spaces.
  • Show four LEVEL: n lines, in the order DEBUG, INFO, WARNING, ERROR, with the number of valid lines of each level.
  • Show Invalid lines: k with the lines that do not match the format.
  • Show Day with most errors: YYYY-MM-DD (n) with the day that has the most ERROR lines (on a tie, the earlier day), or No errors if there are none.
  • Show Busiest hour: HH (n) with the hour of the day (00-23) with the most valid lines (on a tie, the smaller hour), or No records if there are no valid lines.
Input
5
2026-03-01 10:15:32 INFO Servidor iniciado
2026-03-01 10:20:01 ERROR Disco lleno
2026-03-02 11:00:00 ERROR Sin memoria
linea rota
2026-03-02 11:30:10 WARNING Memoria alta
Output
DEBUG: 0
INFO: 1
WARNING: 1
ERROR: 2
Invalid lines: 1
Day with most errors: 2026-03-01 (1)
Busiest hour: 10 (2)

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise