Added logic to load config from json & improved hosting and service providing

This commit is contained in:
2020-11-28 15:13:54 +01:00
parent ff577b121e
commit 44ffb4e574
29 changed files with 285 additions and 141 deletions

View File

@@ -0,0 +1,8 @@
{
"LoggingSettings": {
"Path": "logs/",
"Filename": "log_$start_time.log",
"ConsoleLogLevel": "TRACE",
"FileLogLevel": "TRACE"
}
}

View File

@@ -0,0 +1,15 @@
{
"TimeFormatSettings": {
"DateFormat": "%Y-%m-%d",
"TimeFormat": "%H:%M:%S",
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
},
"LoggingSettings": {
"Path": "logs/",
"Filename": "log_$start_time.log",
"ConsoleLogLevel": "ERROR",
"FileLogLevel": "WARN"
}
}

View File

@@ -3,12 +3,9 @@ from typing import Optional
from sh_edraft.configuration.base import ConfigurationBase
from sh_edraft.hosting import ApplicationHost
from sh_edraft.hosting.base import ApplicationBase
from sh_edraft.hosting.model import EnvironmentName
from sh_edraft.logging import Logger
from sh_edraft.logging.base import LoggerBase
from sh_edraft.logging.model import LoggingSettings
from sh_edraft.service.base import ServiceProviderBase
from sh_edraft.time.model import TimeFormatSettings
class Program(ApplicationBase):
@@ -22,40 +19,28 @@ class Program(ApplicationBase):
self._configuration: Optional[ConfigurationBase] = None
def create_application_host(self):
self._app_host = ApplicationHost('CPL_DEV_Test')
self._app_host = ApplicationHost()
self._services = self._app_host.services
self._configuration = self._app_host.configuration
self._app_host.environment.name = EnvironmentName.development
def create_configuration(self):
self._configuration.create()
log_settings = LoggingSettings()
log_settings.from_dict({
"Path": "logs/",
"Filename": "log_$start_time.log",
"ConsoleLogLevel": "TRACE",
"FileLogLevel": "TRACE"
})
time_format_settings = TimeFormatSettings()
time_format_settings.from_dict({
"DateFormat": "%Y-%m-%d",
"TimeFormat": "%H:%M:%S",
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
})
self._configuration.add_config_by_type(LoggingSettings, log_settings)
self._configuration.add_config_by_type(TimeFormatSettings, time_format_settings)
self._configuration.add_environment_variables('PYTHON_')
self._configuration.add_environment_variables('CPL_')
self._configuration.add_argument_variables()
self._configuration.add_json_file(f'appsettings.json')
self._configuration.add_json_file(f'appsettings.{self._configuration.environment.environment_name}.json')
self._configuration.add_json_file(f'appsettings.{self._configuration.environment.host_name}.json', optional=True)
def create_services(self):
self._services.create()
self._services.add_singleton(LoggerBase, Logger)
logger: Logger = self._services.get_service(LoggerBase)
logger.create()
logger.header(self._app_host.name)
logger.header(f'{self._configuration.environment.application_name}:')
logger.debug(__name__, f'Host: {self._configuration.environment.host_name}')
logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}')
logger.debug(__name__, f'Customer: {self._configuration.environment.customer}')
def main(self):
print('RUN')