easy +10 pts

Parse Log Line

Extract timestamp, level, and message from a log line using string methods.

You are given a log line in the following format: `[TIMESTAMP] LEVEL: message` where TIMESTAMP is a date-time string (e.g., `2025-03-04 10:15:30`), LEVEL is a severity level (e.g., INFO, WARNING, ERROR), and message can contain spaces and colons. Write a function `parse_log_line(line)` that takes a single string `line` and returns a dictionary with keys `"timestamp"`, `"level"`, and `"message"` containing the corresponding parts as strings. Assume the log line always follows the exact format (including brackets, the space after the timestamp, and the colon after the level). No extra leading/trailing spaces outside the proper places. Your function should work for any valid log line. Implement it using string methods only (no regex).

Constraints

The input string length is at most 200 characters. Timestamp is a non-empty string without spaces inside (it will not contain spaces). Level is one of INFO, WARNING, ERROR, DEBUG, CRITICAL. Message may be empty? Actually message can be any string, including empty, but there will be a space after the colon? Let's decide: the format is exactly `[TIMESTAMP] LEVEL: message` with a single space after the colon. If message is empty, there is still a space after the colon? The statement says 'message can contain spaces and colons'. To avoid ambiguity, we will ensure message is non-empty in tests. The problem is easy and should be unambiguous.

Example

>>> parse_log_line("[2025-03-04 10:15:30] INFO: User logged in")
{'timestamp': '2025-03-04 10:15:30', 'level': 'INFO', 'message': 'User logged in'}
>>> parse_log_line("[2025-03-04 10:15:30] WARNING: Disk space low")
{'timestamp': '2025-03-04 10:15:30', 'level': 'WARNING', 'message': 'Disk space low'}
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use find() or split() to separate the timestamp from the rest.
After extracting the timestamp, strip the leading '[' and trailing ']'.
The remaining part after timestamp is 'LEVEL: message'. Split on the first colon to get level and message.
Remember to strip the space after the colon from the message.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.