0

Here is my code

import logging

logger = logging.getLogger('test')
logger.setLevel(level=logging.INFO)
logger.info('Hello World')

I expect it to print out 'Hello World'. It does not do so.

Could someone help me understanding why it does not print the message out?

asynts
  • 2,213
  • 2
  • 21
  • 35
Denys
  • 4,287
  • 8
  • 50
  • 80
  • Does this answer your question? [Python logger doesn't adhere to the set level](https://stackoverflow.com/questions/39068465/python-logger-doesnt-adhere-to-the-set-level) – asynts Dec 25 '19 at 19:49

1 Answers1

1

You haven't specified a handler for your logger. The message is therefor propagated to the root handler which has a different log level.

The root logger can be configured as follows:

logging.basicConfig(level=logging.INFO)

Alternatively you can add a handler that forwards the messages to stderr:

logger.addHandler(logging.StreamHandler()) 

This behavior is documented here.

asynts
  • 2,213
  • 2
  • 21
  • 35