When I running the following inside IPython Notebook I don\'t see any output:
import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug(\"test\")
It seems that solutions that worked for older versions of ipython/jupyter no longer work.
Here is a working solution for ipython 7.9.0 (also tested with jupyter server 6.0.2):
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logging.debug("test message")
DEBUG:root:test message
Bear in mind that stderr is the default stream for the logging
module, so in IPython and Jupyter notebooks you might not see anything unless you configure the stream to stdout:
import logging
import sys
logging.basicConfig(format='%(asctime)s | %(levelname)s : %(message)s',
level=logging.INFO, stream=sys.stdout)
logging.info('Hello world!')
Try following:
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logging.debug("test")
According to logging.basicConfig:
Does basic configuration for the logging system by creating a StreamHandler with a default Formatter and adding it to the root logger. The functions debug(), info(), warning(), error() and critical() will call basicConfig() automatically if no handlers are defined for the root logger.
This function does nothing if the root logger already has handlers configured for it.
It seems like ipython notebook call basicConfig (or set handler) somewhere.