Skip to content
dreamcode
dreamcode
Projects
Log Lens
Independent projectPython
Reward: +380 XP
PROJECT BRIEF

Log Lens

Each log line looks like [LEVEL] module: message, for example [ERROR] auth: token expired. Write summarize_logs(lines) that returns:

  • counts: how many lines had each level, as a dictionary
  • noisiest: the module with the most ERROR lines (the one that appears first on a tie), or None if there were no errors
  • skipped: how many lines did not match the format at all

Levels are always capital letters and module names are letters, digits or underscores.

Examples
summarize_logs(['[INFO] web: started', '[ERROR] auth: token expired', '[ERROR] db: timeout', '[ERROR] auth: bad password', 'garbage line', '[WARN] web: slow'])
{'counts': {'INFO': 1, 'ERROR': 3, 'WARN': 1}, 'noisiest': 'auth', 'skipped': 1}
summarize_logs(['[INFO] web: ok'])
{'counts': {'INFO': 1}, 'noisiest': None, 'skipped': 0}
project.py
PYTHON
Saved as you type

Tests

0 of 4 passing
  • mixed log
    summarize_logs(['[INFO] web: started', '[ERROR] auth: token expired', '[ERROR] db: timeout', '[ERROR] auth: bad password', 'garbage line', '[WARN] web: slow'])
    expected {'counts': {'INFO': 1, 'ERROR': 3, 'WARN': 1}, 'noisiest': 'auth', 'skipped': 1}
  • quiet day
    summarize_logs(['[INFO] web: ok'])
    expected {'counts': {'INFO': 1}, 'noisiest': None, 'skipped': 0}
  • empty log
    summarize_logs([])
    expected {'counts': {}, 'noisiest': None, 'skipped': 0}
  • tie goes to the first module
    summarize_logs(['[ERROR] cache: miss', '[ERROR] queue: full'])
    expected {'counts': {'ERROR': 2}, 'noisiest': 'cache', 'skipped': 0}
On the line
+380 XP
Pass all 4 tests to claim it.