Editor

Predict the Output: Log Level Filtering

Beginner · Predict the output · from Python Logging: Stop Using print() for Debugging

From the lesson: Python Logging: Stop Using print() for Debugging

Every airplane has a flight recorder - a "black box" that silently records everything that happens during a flight. If something goes wrong, investigators can replay the recording to figure out exactly what happened and when.

Read the lesson

What will this code print? Remember, when the level is set to WARNING, only WARNING and above are shown.

import logging
logging.basicConfig(level=logging.WARNING, format='%(levelname)s: %(message)s', force=True)

logging.debug('step 1')
logging.info('step 2')
logging.warning('step 3')
logging.error('step 4')
# Type the exact output

More Logging exercises

All Python exercises · 50 practice problems · Error Handling quiz