feat: add TUI-safe logging mode that disables RichHandler

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 12:41:03 -05:00
parent ff40ef7803
commit 08da2c542a
2 changed files with 46 additions and 0 deletions

View File

@@ -77,6 +77,21 @@ def setup_logging(
)
def setup_logging_for_tui() -> None:
"""Reconfigure logging for Textual TUI mode.
Removes the RichHandler (which writes to stdout and corrupts the TUI)
while preserving any file handlers. Call this from the Textual App's
on_mount() before any agent work begins.
"""
from rich.logging import RichHandler
root_logger = logging.getLogger()
root_logger.handlers = [
h for h in root_logger.handlers if not isinstance(h, RichHandler)
]
def get_logger(name: str) -> structlog.stdlib.BoundLogger:
"""Get a named structlog logger.