Importing pygwalker (v0.1.11) changes what logging messages are displayed in the cell output. I can temporarily remove this import to prevent the messages from being logged, but I was wondering if there is an intended way to control the log messages displayed in Jupyter.
This example does not print the log message:
import logging
import numpy
import pandas
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.debug("test")
This example (below) does print the log message:
import pygwalker
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.debug("test")
Is there some way to programmatically determine the log messages that are printed in the cell output that can be performed regardless of the package imported?
Logging in Jupyter Notebook can be configured by adding (or removing) logging.StreamHandler
from a logger. Here are a few simple solutions to the issue in the question is the following:
logging.StreamHandler
from the logger in questionlogger.handlers = list(
filter(
lambda handler: not isinstance(handler, logging.StreamHandler),
logger.handlers
)
)
basicConfig
logging.basicConfig(handlers=[logging.NullHandler()], force=True)
This sets the default handler for any new loggers to be logging.NullHandler()
. force=True
is set because this call would be ignored if an imported package has already called basicConfig
. A disadvantage with this approach is that it will become the default for all new loggers, so it lacks granular control.
logger.handlers.clear()
One potential disadvantage with this approach is if the logger in question had other important handlers configured, this would remove them entirely.