Coverage for opt/mealie/lib/python3.12/site-packages/mealie/core/root_logger.py: 88%
18 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 03:04 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 03:04 +0000
1import logging
3from .config import get_app_dirs, get_logging_settings
4from .logger.config import configured_logger
6__root_logger: None | logging.Logger = None
9def get_logger(module=None) -> logging.Logger:
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.
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
20 if __root_logger is None:
21 app_logging_settings = get_logging_settings()
23 mode = "development"
25 if app_logging_settings.TESTING: 25 ↛ 26line 25 didn't jump to line 26 because the condition on line 25 was never true
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 true
28 mode = "production"
30 dirs = get_app_dirs()
32 substitutions = {
33 "DATA_DIR": dirs.DATA_DIR.as_posix(),
34 "LOG_LEVEL": app_logging_settings.LOG_LEVEL.upper(),
35 }
37 __root_logger = configured_logger(
38 mode=mode,
39 config_override=app_logging_settings.LOG_CONFIG_OVERRIDE,
40 substitutions=substitutions,
41 )
43 if module is None:
44 return __root_logger
46 return __root_logger.getChild(module)