Skip to content

Commit 8b1f488

Browse files
committed
libtmux(feat[logging]): add Window/Server lifecycle logs
why: Window and Server objects lacked INFO-level lifecycle logging, unlike Session and Pane which already had it. This creates gaps in observability for session creation and window rename/kill operations. what: - window.py rename_window: add logger.info with conditional extra - window.py kill: add logger.info with conditional extra - server.py new_session: add logger.info for session created event - server.py new_session: add logger.info for existing session killed - server.py new_session: add logger.debug for session creation start
1 parent fd457a0 commit 8b1f488

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/libtmux/server.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,17 @@ def new_session(
598598

599599
session_data = parse_output(session_stdout)
600600

601-
return Session(server=self, **session_data)
601+
session = Session(server=self, **session_data)
602+
603+
logger.info(
604+
"session created",
605+
extra={
606+
"tmux_subcommand": "new-session",
607+
"tmux_session": session.session_name,
608+
},
609+
)
610+
611+
return session
602612

603613
#
604614
# Relations

src/libtmux/window.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,15 @@ def rename_window(self, new_name: str) -> Window:
488488
self.window_name = new_name
489489
self.refresh()
490490

491+
extra: dict[str, str] = {
492+
"tmux_subcommand": "rename-window",
493+
}
494+
if self.window_name is not None:
495+
extra["tmux_window"] = str(self.window_name)
496+
if self.window_id is not None:
497+
extra["tmux_target"] = str(self.window_id)
498+
logger.info("window renamed", extra=extra)
499+
491500
return self
492501

493502
def kill(
@@ -543,6 +552,16 @@ def kill(
543552
if proc.stderr:
544553
raise exc.LibTmuxException(proc.stderr)
545554

555+
msg = "windows killed" if all_except else "window killed"
556+
extra: dict[str, str] = {
557+
"tmux_subcommand": "kill-window",
558+
}
559+
if self.window_name is not None:
560+
extra["tmux_window"] = str(self.window_name)
561+
if self.window_id is not None:
562+
extra["tmux_target"] = str(self.window_id)
563+
logger.info(msg, extra=extra)
564+
546565
def move_window(
547566
self,
548567
destination: str = "",

0 commit comments

Comments
 (0)