nickpick nickpick - 25 days ago 7
Python Question

Python logger not outputing anything despite loglevel is set

I know this question has been asked many times before but I've never seen that after setting the level it doesn't outputting anything. Any suggestions what I do wrong? The following example does not output anything.

import logging
logger=logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.debug("Test")

Answer

You need to have a handler:

import logging
logger=logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())  # <<< Add a handler
logger.debug("Test")