Medium
Nested Log Prefixes
A
log(msg) function prints the current prefix plus msg. prefix(p) is a context manager that adds p + ': ' to the prefix and restores it afterwards. Read commands until END: in NAME opens a prefix (use an ExitStack or a stack of managers), out closes the latest one and log TEXT logs.Input
Commands, then END.
Output
Lines.
Sample 1
Input
log start in db log connect in query log run out log done out log end END
Output
start db: connect db: query: run db: done end
Sample 2
Input
log hi END
Output
hi
Output appears here