notebook-fix-logging
Use idiom for controlling logging in Jupyter notebooks
SKILL.md.claude/skills/notebook.fix_logging/SKILL.md
GitHubGoal
Implement the instructions in
.claude/skills/notebook.rules.mdunder## Use Standard Template StructureUse the structure from
.claude/templates/notebook.template.pyfor notebook initializationUse
displayThe local utility
*_utils.pyshould have a function likeimport helpers.hnotebook as hnotebo def init_loggers(notebook_log: logging.Logger) -> None: """ Wire the notebook logger into the utils logger. :param notebook_log: logger owned by the notebook """ hnotebo.init_loggers(notebook_log, utils_log=_LOG)hnotebo.init_loggers()already callsconfig_notebook(), initializeshdbgat INFO level, and redirects the notebook and utils loggers to print- For a third-party logger (e.g.,
causalml), redirect it insideinit_loggers()withhnotebo.set_logger_to_print():hnotebo.set_logger_to_print(logging.getLogger("causalml"))
The last setup cell in the notebook calls
utils.init_loggers(_LOG), notlogging.basicConfig()orhdbg.init_logger()
Workflow
Sync Notebook
- At the end, sync the paired
.pyfile with Jupytext following the conventions in# Code Architecture and Responsibility->## Utilities vs. Notebook Responsibilitiesin.claude/skills/notebook.rules.md
Conventions
- Always follow the conventions and guidelines in
.claude/skills/notebook.rules.md
Verification
- Confirm the notebook init cell matches
.claude/templates/notebook.template.py - Confirm
utils.init_loggers()is called and log messages print in the notebook - Confirm the
.ipynband paired.pyfile are in sync via Jupytext