Loggers#
A logger is the main entry point of the logging
library, allowing you to define top-level behavior.
import logging
List all loggers#
It’s usefull to acesss all loggers available now. All loogets defined in the cureent interprier state is defined in the logging.Logger.manager.loggerDict
.
The following cell demonstrates how loggerDict
looks like for the current jupyter notebook.
logging.Logger.manager.loggerDict
{'concurrent.futures': <Logger concurrent.futures (WARNING)>,
'concurrent': <logging.PlaceHolder at 0x77013bedf040>,
'asyncio': <Logger asyncio (WARNING)>,
'tornado.access': <Logger tornado.access (WARNING)>,
'tornado': <Logger tornado (WARNING)>,
'tornado.application': <Logger tornado.application (WARNING)>,
'tornado.general': <Logger tornado.general (WARNING)>,
'stack_data.serializing': <Logger stack_data.serializing (WARNING)>,
'stack_data': <logging.PlaceHolder at 0x77013ad56fe0>,
'parso': <Logger parso (WARNING)>,
'prompt_toolkit.buffer': <Logger prompt_toolkit.buffer (WARNING)>,
'prompt_toolkit': <logging.PlaceHolder at 0x77013a970d60>,
'parso.python.diff': <Logger parso.python.diff (WARNING)>,
'parso.python': <logging.PlaceHolder at 0x77013a3eb040>,
'parso.cache': <Logger parso.cache (WARNING)>,
'Comm': <Logger Comm (WARNING)>,
'ipykernel.comm': <Logger ipykernel.comm (WARNING)>,
'ipykernel': <logging.PlaceHolder at 0x770139edcaf0>,
'IPKernelApp': <Logger IPKernelApp (DEBUG)>}
Disable#
Some loggers can be disabled. A logger is disabled if it’s disabled
property takes the value false
.
The following example shows how created logger can be disabled.
logger = logging.getLogger("disable_test_logger")
logger.warning("beep")
logger.disabled = True
logger.warning("beep")
logger.disabled = False
beep
Even though we run the looger.warning("beep")
command twice, there is only one beep
message because we just set disabled=True
before the second beep
.