pythonlogging

Turn on debug logging in python


I'm trying to turn on debug logging in python 3.5.2:

import logging
log = logging.getLogger('test')
log.setLevel(logging.DEBUG)

log.warn('warn')
log.debug('debug')

log.root.setLevel(logging.DEBUG)
log.debug('debug again')

However, this only prints warn. What am I missing?


Solution

  • This should accomplish what you want

    logging.basicConfig(level=logging.DEBUG)
    

    …followed by

    log = logging.getLogger('test')
    log.debug('debug')