As a sample code that is rolling around
python
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.info("hoge")
I see this kind of thing, but it doesn't work even if I copy it as it is.
No handlers could be found for logger "__main__"
This error message appears on the second line.
Since __name__
is the file name specified first, it becomes " __ main__ "
.
python
import logging
logging.info("ho")
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.info("hoge")
For some reason, it works if you spit something out of the logging.
module even once.
INFO:__main__:hoge
logger cannot go without giving a config.
python
import logging
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.info("hoge")
When logging.info ("")
is set, the operation equivalent tologging.basicConfig ()
is performed internally.
Recommended Posts