'Why can't I use the logging module on Python 3.10?
A simple code I want to run to discover what "logging" module is:
import logging
logging.debug('This is a debug message')
This code is not working for me. I'm on SublimeText 3, my Python version is 3.10
I've got pip version 22.0.4, ez_setup version 0.9 and setuptools version 61
The logging module is in my lib:(picture) I don't understand... Can you help me please?
Solution 1:[1]
The default output for Python logging is stdout, so if it is working it must print to the console. Why is not it working? Because first of all you must get a logger
logger = logging.getLogger('__main__')
Then you must set the level. By default DEBUG is not logging.
logger.setLevel(logging.DEBUG)
Now it must work
logger.debug('your message')
Solution 2:[2]
According to the docs, the root logger is created with level WARNING, hence the debug call is ignored. You can change the level with setLevel:
>>> import logging
>>> logging.debug('test')
>>> logging.getLogger().setLevel(logging.DEBUG)
>>> logging.debug('test')
DEBUG:root:test
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Megacodist |
| Solution 2 | a_guest |
