stanza.jupyter.logs

Log streaming for Jupyter notebooks and servers.

Module Contents

Functions

NameDescription
_wait_for_logWait for log file to exist or timeout.
_print_tailPrint last N lines from log file with proper terminal alignment.
_stream_logRead and print new log lines with proper terminal alignment.
followStream log file until Ctrl+C.
attachStream log file with active kernel control.

API

1stanza.jupyter.logs._wait_for_log(
2 log_file: pathlib.Path, timeout: float = 30.0
3) -> None

Wait for log file to exist or timeout.

Polls for the log file’s existence, displaying a waiting message to stderr. Exits with status 1 if the file doesn’t appear within the timeout period.

Parameters:

log_file
pathlib.Path

Path to the log file to wait for

timeout
floatDefaults to 30.0

Maximum seconds to wait before exiting

1stanza.jupyter.logs._print_tail(
2 log_file: pathlib.Path, lines: int
3) -> None

Print last N lines from log file with proper terminal alignment.

Parameters:

log_file
pathlib.Path

Path to the log file to read

lines
int

Number of lines to print from the end of the file

1stanza.jupyter.logs._stream_log(
2 f: object,
3 poll_interval: float,
4 log_file: pathlib.Path
5) -> None

Read and print new log lines with proper terminal alignment.

Strips carriage return artifacts from progress bars and formats output for proper terminal display. Exits if the log file is deleted.

Parameters:

f
object

Open file handle positioned at the current read position

poll_interval
float

Seconds to sleep when no new data is available

log_file
pathlib.Path

Path to the log file (for existence checking)

1stanza.jupyter.logs.follow(
2 log_file: pathlib.Path,
3 lines: int = 10,
4 poll_interval: float = 0.1
5) -> None

Stream log file until Ctrl+C.

Displays the last N lines of the log file, then continuously streams new lines as they are written. Exits gracefully on Ctrl+C.

Parameters:

log_file
pathlib.Path

Path to the log file to follow

lines
intDefaults to 10

Number of initial lines to display from the end of the file

poll_interval
floatDefaults to 0.1

Seconds to wait between checks for new content

1stanza.jupyter.logs.attach(
2 log_file: pathlib.Path,
3 kill_callback: collections.abc.Callable[[], None],
4 lines: int = 10,
5 poll_interval: float = 0.1
6) -> None

Stream log file with active kernel control.

Displays the last N lines of the log file, then continuously streams new lines. Ctrl+C kills the kernel via the callback. ESC exits without killing (press twice for safety).

Parameters:

log_file
pathlib.Path

Path to the log file to follow

kill_callback
collections.abc.Callable[[], None]

Function to call when Ctrl+C is pressed

lines
intDefaults to 10

Number of initial lines to display from the end of the file

poll_interval
floatDefaults to 0.1

Seconds to wait between checks for new content