Robert Sim
Robert Sim

Reputation: 1560

How does python logging level interact with logging.info()?

Is this a bug? setLevel seems to set the appropriate level, but logging.info has no effect:

>>> import logging
>>> logger=logging.getLogger()
>>> logger.warning('foo')
foo
>>> logger.info('foo')
>>> logger.getEffectiveLevel()
20  # this is logging.INFO.  Why didn't .info() work?
>>> logger.setLevel(logging.INFO)
>>> logger.getEffectiveLevel()
20
>>> logger.setLevel(logging.DEBUG)
>>> logger.info('foo')
>>> logger.getEffectiveLevel()
10

Upvotes: 0

Views: 40

Answers (1)

Denis-Alexandru Nica
Denis-Alexandru Nica

Reputation: 316

In the absence of any logging configuration, logging uses a last-resort handler that handles only messages of level WARNING and above.

If you run

logging.basicConfig()

it will behave as expected.

Upvotes: 1

Related Questions