stanza.jupyter.startup
Automatic logging of Jupyter notebook cell I/O to disk.
Hooks stdout, stderr, and exceptions. Writes to notebook_name.log if the notebook path can be discovered via the Jupyter sessions API, otherwise jupyter_session.log.
Module Contents
Classes
Functions
API
Get the current IPython instance if running in IPython.
Returns:
IPython instance if available, None otherwise
Check if the IPython instance is running in a Jupyter kernel.
Parameters:
IPython instance to check
Returns:
True if running in a Jupyter kernel, False otherwise
Extract the kernel ID from the IPython kernel connection file.
Parameters:
IPython instance containing kernel configuration
Returns:
Kernel ID string if found, None otherwise
Find the notebook path by querying running Jupyter servers for the kernel ID.
Iterates through all running Jupyter servers and queries their sessions API to match the kernel ID with an active notebook session.
Parameters:
Kernel ID to search for
Returns:
Absolute path to the notebook file if found, None otherwise
Append text to the log file, silently ignoring write failures.
Parameters:
Path to the log file
Text content to append
Tee stream wrapper that duplicates writes to a log file.
Acts as a transparent proxy for a stream (like sys.stdout or sys.stderr) while also writing all output to a log file.
Initialization
Initialize tee with the original stream and log file path.
Parameters:
Parameters:
- original: Original stream to wrap (e.g., sys.stdout)
- log_path: Path to the log file for duplicated output
Write text to both the original stream and the log file.
Parameters:
Text content to write
Returns:
Number of characters written to the original stream
Flush the original stream, ignoring errors.
Delegate attribute access to the original stream.
Parameters:
Attribute name to access
Returns:
Value of the attribute from the original stream
Install logging hooks for stdout, stderr, and IPython exceptions.
Writes a header to the log file, wraps sys.stdout and sys.stderr with _Tee instances, and hooks IPython’s showtraceback method to log exception tracebacks.
Parameters:
IPython instance to install hooks on
Path to the log file for output
Entry point: set up auto-logging for the current Jupyter kernel session.
Discovers the notebook path from the running Jupyter servers, creates a log file, and installs logging hooks. Falls back to jupyter_session.log if the notebook path cannot be determined.

