I'm trying to get Python to log stuff and, despite having read over the logging docs and how-to, I don't understand its behavior.
I set the global log level and then tried logging something:
logger = logging.getLogger()
print("Initially should be warn: %d" % logger.getEffectiveLevel())
logger.setLevel(logging.DEBUG)
print("Logger level: %d" % logger.getEffectiveLevel())
logger.info("Maybe I am printed?")
But running python my_script.py
just prints:
Initially should be warn: 30
Logger level: 10
However, if I add a line logging.info
call, e.g.,
logger = logging.getLogger()
print("Initially should be warn: %d" % logger.getEffectiveLevel())
logger.setLevel(logging.DEBUG)
print("Logger level: %d" % logger.getEffectiveLevel())
logging.info("I am printed")
logger.info("Maybe I am printed?")
then the logging all shows up:
Initially should be warn: 30
Logger level: 10
INFO:root:I am printed
INFO:root:Maybe I am printed?
What is logging.info
doing?