Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 1.07 KB

instructions.md

File metadata and controls

45 lines (30 loc) · 1.07 KB

In this exercise you'll be processing log-lines.

Each log line is a string formatted as follows: "[<LEVEL>]: <MESSAGE>".

There are three different log levels:

  • INFO
  • WARNING
  • ERROR

You have three tasks, each of which will take a log line and ask you to do something with it.

1. Extract a message from a log line

Implement the extract_message to return a log line's message:

>>> extract_message("[ERROR]: Invalid operation")
'Invalid operation'

The message should be trimmed of any whitespace.

>>> extract_message("[ERROR]: Invalid operation.\t\n")
'Invalid operation.'

2. Change a message's loglevel.

Implement the change_log_level function to replace a log line's current log level with a new one:

>>> change_log_level("[INFO]: Fatal Error.", "ERROR")
'[ERROR]: Fatal Error.'

3. Reformat a log line

Implement the reformat function to reformat the log line, putting the message first and the log level after it in parentheses:

>>> reformat("[INFO]: Operation completed")
'Operation completed (info)'