Coverage for src/config_logging.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-16 04:41 +0000

1"""Logging utilities for configuration-related operations. 

2 

3Provides reusable logging functions to separate logging concerns from 

4config retrieval logic, following Single Responsibility Principle. 

5""" 

6 

7__author__ = "Mandar Patil (mandarons@pm.me)" 

8 

9from typing import Any 

10 

11from src import get_logger 

12 

13LOGGER = get_logger() 

14 

15 

16def log_config_not_found_warning(config_path: list[str], message: str) -> None: 

17 """Log a warning when a config path is not found. 

18 

19 Args: 

20 config_path: List of config keys forming the path 

21 message: Custom warning message to log 

22 """ 

23 from src.config_utils import config_path_to_string 

24 

25 path_str = config_path_to_string(config_path) 

26 LOGGER.warning(f"{path_str} {message}") 

27 

28 

29def log_config_found_info(message: str) -> None: 

30 """Log an info message when config value is found and processed. 

31 

32 Args: 

33 message: Info message to log 

34 """ 

35 LOGGER.info(message) 

36 

37 

38def log_config_debug(message: str) -> None: 

39 """Log a debug message for config processing. 

40 

41 Args: 

42 message: Debug message to log 

43 """ 

44 LOGGER.debug(message) 

45 

46 

47def log_config_error(config_path: list[str], message: str) -> None: 

48 """Log an error for config validation issues. 

49 

50 Args: 

51 config_path: List of config keys forming the path 

52 message: Error message to log 

53 """ 

54 from src.config_utils import config_path_to_string 

55 

56 path_str = config_path_to_string(config_path) 

57 LOGGER.error(f"{path_str}: {message}") 

58 

59 

60def log_invalid_config_value(config_path: list[str], invalid_value: Any, valid_values: str) -> None: 

61 """Log warning about invalid config value. 

62 

63 Args: 

64 config_path: List of config keys forming the path 

65 invalid_value: The invalid value that was found 

66 valid_values: Description of valid values 

67 """ 

68 from src.config_utils import config_path_to_string 

69 

70 path_str = config_path_to_string(config_path) 

71 LOGGER.warning(f"Invalid value '{invalid_value}' at {path_str}. Valid values: {valid_values}")