42

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?

1 Answer 1

56

This should accomplish what you want

logging.basicConfig(level=logging.DEBUG)

…followed by

log = logging.getLogger('test')
log.debug('debug') 
2
  • 6
    Thanks for your answer. Using the root logger logging will also print logs from other python libraries. Is there a way to print debug-level logs using a logger obtained via logging.getLogger(), insted? Just like in the example provided by the OP. Commented Jan 22, 2022 at 12:07
  • @GuidoWalterPettinari this seemed to work for me (in other words, use log instead of logging): logging.basicConfig(level=logging.DEBUG) followed by log = logging.getLogger('test') followed by log.debug('debug')
    – gMale
    Commented Apr 24, 2022 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.