Coverage for opt/mealie/lib/python3.12/site-packages/mealie/core/root_logger.py: 88%

18 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-25 15:32 +0000

1import logging 1a

2 

3from .config import get_app_dirs, get_logging_settings 1a

4from .logger.config import configured_logger 1a

5 

6__root_logger: None | logging.Logger = None 1a

7 

8 

9def get_logger(module=None) -> logging.Logger: 1a

10 """ 

11 Get a logger instance for a module, in most cases module should not be 

12 provided. Simply using the root logger is sufficient. 

13 

14 Cases where you would want to use a module specific logger might be a background 

15 task or a long running process where you want to easily identify the source of 

16 those messages 

17 """ 

18 global __root_logger 

19 

20 if __root_logger is None: 1abcdefghijklmn

21 app_logging_settings = get_logging_settings() 1a

22 

23 mode = "development" 1a

24 

25 if app_logging_settings.TESTING: 25 ↛ 26line 25 didn't jump to line 26 because the condition on line 25 was never true1a

26 mode = "testing" 

27 elif app_logging_settings.PRODUCTION: 27 ↛ 30line 27 didn't jump to line 30 because the condition on line 27 was always true1a

28 mode = "production" 1a

29 

30 dirs = get_app_dirs() 1a

31 

32 substitutions = { 1a

33 "DATA_DIR": dirs.DATA_DIR.as_posix(), 

34 "LOG_LEVEL": app_logging_settings.LOG_LEVEL.upper(), 

35 } 

36 

37 __root_logger = configured_logger( 1a

38 mode=mode, 

39 config_override=app_logging_settings.LOG_CONFIG_OVERRIDE, 

40 substitutions=substitutions, 

41 ) 

42 

43 if module is None: 1abcdefghijklmn

44 return __root_logger 1abcdefghijklmn

45 

46 return __root_logger.getChild(module) 1a