One Line in the Log

Python for AIMedium+10 XP+10

One Line in the Log

Programs often write one line of text per event to a log.

Task: write log_line(level, *words, **fields) that builds one log line:

  1. Start with level.
  2. Then each of the words, each after a single space.
  3. Then, for each field, | name=value — in the order the fields were passed.

With no words and no fields, the line is just the level.

Examples

log_line("WARN", "disk", "almost", "full", user="ada", free=3)
returns 'WARN disk almost full | user=ada | free=3'
level = "INFO"
returns 'INFO'

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run