#915 - Synced with dev

This commit is contained in:
Chris McCarthy
2023-06-09 15:49:48 +01:00
parent 0dbd89e5cb
commit f5e195604f
15 changed files with 426 additions and 322 deletions

View File

@@ -7,11 +7,33 @@ from logging.handlers import RotatingFileHandler
from pathlib import Path
from typing import Final
import pkg_resources
import yaml
from platformdirs import PlatformDirs
_PLATFORM_DIRS: Final[PlatformDirs] = PlatformDirs(appname="primaite")
"""An instance of `PlatformDirs` set with appname='primaite'."""
def _get_primaite_config():
config_path = _PLATFORM_DIRS.user_config_path / "primaite_config.yaml"
if not config_path.exists():
config_path = Path(
pkg_resources.resource_filename(
"primaite", "setup/_package_data/primaite_config.yaml"
)
)
with open(config_path, "r") as file:
primaite_config = yaml.safe_load(file)
return primaite_config
_PRIMAITE_CONFIG = _get_primaite_config()
# PrimAITE config items
_LOG_LEVEL: int = _PRIMAITE_CONFIG["log_level"]
_LOGGER_FORMAT: str = _PRIMAITE_CONFIG["logger_format"]
_USER_DIRS: Final[Path] = Path.home() / "primaite"
"""The users home space for PrimAITE which is located at: ~/primaite."""
@@ -64,12 +86,10 @@ _FILE_HANDLER: Final[RotatingFileHandler] = RotatingFileHandler(
backupCount=9, # Max 100MB of logs
encoding="utf8",
)
_STREAM_HANDLER.setLevel(logging.DEBUG)
_FILE_HANDLER.setLevel(logging.DEBUG)
_STREAM_HANDLER.setLevel(_LOG_LEVEL)
_FILE_HANDLER.setLevel(_LOG_LEVEL)
_LOG_FORMAT_STR: Final[
str
] = "%(asctime)s::%(levelname)s::%(name)s::%(lineno)s::%(message)s"
_LOG_FORMAT_STR: Final[str] = _LOGGER_FORMAT
_STREAM_HANDLER.setFormatter(logging.Formatter(_LOG_FORMAT_STR))
_FILE_HANDLER.setFormatter(logging.Formatter(_LOG_FORMAT_STR))
@@ -88,7 +108,7 @@ def getLogger(name: str) -> Logger:
logging config.
"""
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
logger.setLevel(_LOG_LEVEL)
return logger