Coverage for lintro / utils / logger_setup.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Loguru logger configuration for Lintro. 

2 

3Provides centralized logging setup for both CLI and tool execution contexts. 

4""" 

5 

6import sys 

7from pathlib import Path 

8 

9from loguru import logger 

10 

11 

12def setup_cli_logging() -> None: 

13 """Configure minimal logging for CLI commands (help, version, etc.). 

14 

15 Only shows WARNING and ERROR level messages on console. 

16 No file logging - this is for lightweight CLI operations. 

17 """ 

18 logger.remove() 

19 logger.add( 

20 sys.stderr, 

21 level="WARNING", 

22 format="<level>{message}</level>", 

23 colorize=True, 

24 ) 

25 

26 

27def setup_execution_logging(run_dir: Path, debug: bool = False) -> None: 

28 """Configure full logging for tool execution. 

29 

30 Args: 

31 run_dir: Directory for log files. 

32 debug: If True, show DEBUG messages on console. Otherwise only WARNING+. 

33 """ 

34 logger.remove() 

35 

36 # Console handler - DEBUG if flag set, else WARNING only 

37 console_level = "DEBUG" if debug else "WARNING" 

38 logger.add( 

39 sys.stderr, 

40 level=console_level, 

41 format="{message}", 

42 colorize=True, 

43 ) 

44 

45 # File handler with rotation (captures everything) 

46 run_dir.mkdir(parents=True, exist_ok=True) 

47 debug_log_path: Path = run_dir / "debug.log" 

48 logger.add( 

49 debug_log_path, 

50 level="DEBUG", 

51 format=( 

52 "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | " 

53 "{name}:{function}:{line} | {message}" 

54 ), 

55 rotation="100 MB", 

56 retention=5, 

57 )