refactor: normalize logging to use %-style formatting

Convert f-string logging to lazy %-style interpolation throughout:
- session_manager.py
- cli.py
- terminal_session.py

This follows Python logging best practices for performance (lazy
evaluation) and consistency across the codebase.

Addresses REFACTORING.md item about normalizing logging style.
This commit is contained in:
GitHub Copilot
2026-01-24 10:26:53 +00:00
parent 0086cf76b0
commit ea78ba7ff2
3 changed files with 14 additions and 14 deletions
+6 -6
View File
@@ -139,7 +139,7 @@ def app(
textual-webterm -a ./calculator.py:CalculatorApp # Serve from file
"""
VERSION = version("textual-webterm")
log.info(f"textual-webterm v{VERSION}")
log.info("textual-webterm v%s", VERSION)
if constants.DEBUG:
log.warning("DEBUG env var is set; logs may be verbose!")
@@ -184,10 +184,10 @@ def app(
else:
# Module path - validate module and class names
if not module_part.replace(".", "").replace("_", "").isalnum():
log.error(f"Invalid module path: {module_part}")
log.error("Invalid module path: %s", module_part)
sys.exit(1)
if not class_name.isidentifier():
log.error(f"Invalid class name: {class_name}")
log.error("Invalid class name: %s", class_name)
sys.exit(1)
run_command = (
f'python3 -c "from {module_part} import {class_name}; {class_name}().run()"'
@@ -195,16 +195,16 @@ def app(
app_name = getattr(app_class, "TITLE", None) or class_name
server.add_app(app_name, run_command, "")
log.info(f"Serving Textual app: {app_path}")
log.info("Serving Textual app: %s", app_path)
elif command:
# Run command as terminal
server.add_terminal("Terminal", command, "")
log.info(f"Serving terminal: {command}")
log.info("Serving terminal: %s", command)
elif not landing_apps:
# Run default shell
terminal_command = os.environ.get("SHELL", "/bin/sh")
server.add_terminal("Terminal", terminal_command, "")
log.info(f"Serving terminal: {terminal_command}")
log.info("Serving terminal: %s", terminal_command)
def _run_async():
if constants.WINDOWS:
+4 -4
View File
@@ -59,7 +59,7 @@ class SessionManager:
route_key = self.routes.get_key(session_id)
if route_key is not None:
del self.routes[route_key]
log.debug(f"Session {session_id} ended")
log.debug("Session %s ended", session_id)
async def close_all(self, timeout: float = 3.0) -> None:
"""Close app sessions.
@@ -132,20 +132,20 @@ class SessionManager:
session_id,
app.command,
)
log.info(f"Created terminal session {session_id}")
log.info("Created terminal session %s", session_id)
else:
session_process = AppSession(
self.path,
app.command,
session_id,
)
log.info(f"Created app session {session_id}")
log.info("Created app session %s", session_id)
self.sessions[session_id] = session_process
self.routes[route_key] = session_id
await session_process.open(*size)
log.debug(f"Session {session_id} opened and ready")
log.debug("Session %s opened and ready", session_id)
return session_process
+4 -4
View File
@@ -54,7 +54,7 @@ class TerminalSession(Session):
yield "command", self.command
async def open(self, width: int = 80, height: int = 24) -> None:
log.info(f"Opening terminal session {self.session_id} with command: {self.command}")
log.info("Opening terminal session %s with command: %s", self.session_id, self.command)
pid, master_fd = pty.fork()
self.pid = pid
self.master_fd = master_fd
@@ -78,7 +78,7 @@ class TerminalSession(Session):
os.close(master_fd)
self.master_fd = None
raise
log.debug(f"Terminal session {self.session_id} opened successfully")
log.debug("Terminal session %s opened successfully", self.session_id)
def _set_terminal_size(self, width: int, height: int) -> None:
buf = array.array("h", [height, width, 0, 0])
@@ -106,7 +106,7 @@ class TerminalSession(Session):
def update_connector(self, connector: SessionConnector) -> None:
"""Update the connector for reconnection without restarting the session."""
self._connector = connector
log.debug(f"Updated connector for session {self.session_id}")
log.debug("Updated connector for session %s", self.session_id)
async def start(self, connector: SessionConnector) -> asyncio.Task:
self._connector = connector
@@ -158,7 +158,7 @@ class TerminalSession(Session):
except ProcessLookupError:
pass # Process already gone
except Exception as e:
log.warning(f"Error closing terminal session {self.session_id}: {e}")
log.warning("Error closing terminal session %s: %s", self.session_id, e)
async def wait(self) -> None:
if self._task is not None: