From 139422fd3248ef1977d25b209ee9bdbf9aaf72ae Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 17 Sep 2022 11:39:19 +0200 Subject: [PATCH] Added error message when logging configuration not exists --- src/cpl_core/dependency_injection/service_provider.py | 2 +- src/cpl_core/logging/logger_service.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cpl_core/dependency_injection/service_provider.py b/src/cpl_core/dependency_injection/service_provider.py index acf3cb95..0819432b 100644 --- a/src/cpl_core/dependency_injection/service_provider.py +++ b/src/cpl_core/dependency_injection/service_provider.py @@ -93,7 +93,7 @@ class ServiceProvider(ServiceProviderABC): self._scope = scope def create_scope(self) -> ScopeABC: - sb = ScopeBuilder(ServiceProvider(copy.deepcopy(self._service_descriptors), self._configuration, self._database_context)) + sb = ScopeBuilder(ServiceProvider(self._service_descriptors, self._configuration, self._database_context)) return sb.build() def get_service(self, service_type: type) -> Optional[object]: diff --git a/src/cpl_core/logging/logger_service.py b/src/cpl_core/logging/logger_service.py index a8b4302b..55261e76 100644 --- a/src/cpl_core/logging/logger_service.py +++ b/src/cpl_core/logging/logger_service.py @@ -4,6 +4,7 @@ import sys import traceback from string import Template +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.console.console import Console from cpl_core.console.foreground_color_enum import ForegroundColorEnum from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC @@ -33,6 +34,9 @@ class Logger(LoggerABC): self._log_settings: LoggingSettings = logging_settings self._time_format_settings: TimeFormatSettings = time_format + self._check_for_settings(self._time_format_settings, TimeFormatSettings) + self._check_for_settings(self._log_settings, LoggingSettings) + self._log = Template(self._log_settings.filename).substitute( date_time_now=self._env.date_time_now.strftime(self._time_format_settings.date_time_format), start_time=self._env.start_time.strftime(self._time_format_settings.date_time_log_format) @@ -43,6 +47,12 @@ class Logger(LoggerABC): self.create() + def _check_for_settings(self, settings: ConfigurationModelABC, settings_type: type): + self._level = LoggingLevelEnum.OFF + self._console = LoggingLevelEnum.FATAL + if settings is None: + self.fatal(__name__, f'Configuration for {settings_type} not found') + def _get_datetime_now(self) -> str: r"""Returns the date and time by given format