Skip to content

Stop Using "print" for Debugging

2017-10-12 Discuss

My favorite quickstart guide to the Python logging module, by Al Sweigart:

Stop Using "print" for Debugging: A 5 Minute Quickstart Guide to Python’s logging Module

This is a slight tweak to that pattern, which adds the name of the logging source and an example of disabling selected log sources.

import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logging.getLogger('urllib3').setLevel(logging.CRITICAL)
logging.debug('This is a log message.')