Objective
Create a Python program that uses the logging module to record messages with different levels and show only the important ones.
Instructions
- Import
loggingandsys. The first line of the input is the minimum level (DEBUG,INFO,WARNING,ERRORorCRITICAL). Configure the logging withlogging.basicConfig(level=getattr(logging, minimum), format="%(levelname)s: %(message)s", stream=sys.stdout, force=True). - Read an integer
nand thennlines with the formatLEVEL message(split withsplit(" ", 1)). Record each message withlogging.log(getattr(logging, level), message). loggingwill show only the messages whose level is equal to or higher than the minimum, with the formatLEVEL: message.- At the end show with
printthe lineReceived: N.
WARNING
4
INFO server started
ERROR disk full
DEBUG x = 3
WARNING low memory
ERROR: disk full
WARNING: low memory
Received: 4
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise