Editor

Fix the Bug: Missing Messages

Intermediate · Fix the bug · 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

This code should show all five log messages, but only some appear. Find and fix the bug so that all five messages are displayed.

Expected output:

DEBUG: Starting
INFO: Processing
WARNING: Slow query
ERROR: Connection lost
CRITICAL: System down
import logging
import sys
logging.basicConfig(level=logging.ERROR, format='%(levelname)s: %(message)s', stream=sys.stdout, force=True)
logging.debug('Starting')
logging.info('Processing')
logging.warning('Slow query')
logging.error('Connection lost')
logging.critical('System down')

More Logging exercises

All Python exercises · 50 practice problems · Error Handling quiz