Coverage for src/lilbee/cli/tui/log_routing.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-11-06 08:17 +0000

1"""TUI log file routing: rotating file handler that survives the stderr strip.""" 

2 

3from __future__ import annotations 

4 

5import logging 

6from pathlib import Path 

7 

8from lilbee.cli.log_routing import attach_rotating_file_handler 

9from lilbee.core.config import cfg 

10 

11_TUI_LOG_DIR_NAME = "logs" 

12_TUI_LOG_FILE_NAME = "tui.log" 

13_MAX_BYTES = 1_048_576 # 1 MiB 

14_BACKUP_COUNT = 5 

15 

16 

17def tui_log_path() -> Path: 

18 """Where the TUI's log file is, or will be, at ``cfg.data_root/logs/tui.log``.""" 

19 return cfg.data_root / _TUI_LOG_DIR_NAME / _TUI_LOG_FILE_NAME 

20 

21 

22def setup_tui_log_file() -> Path: 

23 """Install a RotatingFileHandler at ``cfg.data_root/logs/tui.log``. Idempotent.""" 

24 log_path = tui_log_path() 

25 log_path.parent.mkdir(parents=True, exist_ok=True) 

26 attach_rotating_file_handler( 

27 log_path, 

28 max_bytes=_MAX_BYTES, 

29 backup_count=_BACKUP_COUNT, 

30 level=logging.getLogger().getEffectiveLevel(), 

31 ) 

32 return log_path