drsealks
drsealks

Reputation: 2354

logger doesn't output info level even though it is enabled

I'm creating a logger object. Set logging level to logging.INFO. After this I do the following:

>>> import logging
>>> logger = logging.getLogger('mylogger')
>>> logger.setLevel(logging.INFO)
>>> logger.isEnabledFor(logging.INFO)
True

Ok, now try this:

logger.info('123')

The last line prints nothing. However:

>>> logger.critical(123)
123

I know it has to be something very simple that I'm missing. What would that be?

Thanks

Upvotes: 0

Views: 68

Answers (1)

djromero
djromero

Reputation: 19641

You need to add a handler, because by default there is none and it'll log only levels above a predefined last resort level.

Add this code after the line with getLogger:

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
logger.addHandler(console_handler)

Also, look at the examples in the official tutorial.

Upvotes: 1

Related Questions