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 lessonThis 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 downimport 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
- Predict the Output: Log Level FilteringBeginner
- Add Logging to a FunctionBeginner
- Build a Login Validator with LoggingIntermediate
- Refactor: Replace print() with LoggingIntermediate
All Python exercises · 50 practice problems · Error Handling quiz