0

I'm unable to set my logger to the correct level in python. According to this geeksforgeeks post, the following script should print all logging statements to the console, but it only prints the warning.

import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

# Should pring everything
logger.debug("debug")
logger.info("info")
logger.warning("warning") # only prints this

but the output is only

warning

I am thoroughly confused, especially because my script was working as expected yesterday. Nothing in other similar posts has worked yet. Can anyone explain this odd behaviour?

Executed with Python version 3.9.5

dcxst
  • 173
  • 3
  • 8
  • 1
    In the article they are calling `basicConfig()`. You don't have to pass any arguments to it, but you do have to call it to get the right behavior. See [What happens if no configuration is provided](https://docs.python.org/3/howto/logging.html#what-happens-if-no-configuration-is-provided) for details. – Bill the Lizard May 05 '22 at 12:47

1 Answers1

1

You need to run logging.basicConfig() in order for logging to work correctly.

matszwecja
  • 6,357
  • 2
  • 10
  • 17