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

59

This should accomplish what you want

logging.basicConfig(level=logging.DEBUG)

…followed by

log = logging.getLogger('test')
log.debug('debug') 
Sign up to request clarification or add additional context in comments.

2 Comments

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.
@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')

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.