2020-11-22 20:17:57 +01:00
|
|
|
import traceback
|
|
|
|
from typing import Optional
|
|
|
|
|
2021-03-03 10:47:52 +01:00
|
|
|
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
|
|
|
from cpl.console.console import Console
|
|
|
|
from cpl.console.foreground_color import ForegroundColor
|
|
|
|
from cpl.logging.logging_level import LoggingLevel
|
|
|
|
from cpl.logging.logging_settings_name import LoggingSettingsName
|
2020-11-22 20:17:57 +01:00
|
|
|
|
|
|
|
|
2021-03-03 10:47:52 +01:00
|
|
|
class LoggingSettings(ConfigurationModelABC):
|
2020-11-22 20:17:57 +01:00
|
|
|
|
|
|
|
def __init__(self):
|
2021-03-03 10:47:52 +01:00
|
|
|
ConfigurationModelABC.__init__(self)
|
2020-11-22 20:17:57 +01:00
|
|
|
self._path: Optional[str] = None
|
|
|
|
self._filename: Optional[str] = None
|
|
|
|
self._console: Optional[LoggingLevel] = None
|
|
|
|
self._level: Optional[LoggingLevel] = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def path(self) -> str:
|
|
|
|
return self._path
|
|
|
|
|
|
|
|
@path.setter
|
|
|
|
def path(self, path: str) -> None:
|
|
|
|
self._path = path
|
|
|
|
|
|
|
|
@property
|
|
|
|
def filename(self) -> str:
|
|
|
|
return self._filename
|
|
|
|
|
|
|
|
@filename.setter
|
|
|
|
def filename(self, filename: str) -> None:
|
|
|
|
self._filename = filename
|
|
|
|
|
|
|
|
@property
|
|
|
|
def console(self) -> LoggingLevel:
|
|
|
|
return self._console
|
|
|
|
|
|
|
|
@console.setter
|
|
|
|
def console(self, console: LoggingLevel) -> None:
|
|
|
|
self._console = console
|
|
|
|
|
|
|
|
@property
|
|
|
|
def level(self) -> LoggingLevel:
|
|
|
|
return self._level
|
|
|
|
|
|
|
|
@level.setter
|
|
|
|
def level(self, level: LoggingLevel) -> None:
|
|
|
|
self._level = level
|
|
|
|
|
|
|
|
def from_dict(self, settings: dict):
|
|
|
|
try:
|
2020-11-28 15:13:54 +01:00
|
|
|
self._path = settings[LoggingSettingsName.path.value]
|
|
|
|
self._filename = settings[LoggingSettingsName.filename.value]
|
|
|
|
self._console = LoggingLevel[settings[LoggingSettingsName.console_level.value]]
|
|
|
|
self._level = LoggingLevel[settings[LoggingSettingsName.file_level.value]]
|
2020-11-22 20:17:57 +01:00
|
|
|
except Exception as e:
|
2020-12-14 21:10:26 +01:00
|
|
|
Console.set_foreground_color(ForegroundColor.red)
|
|
|
|
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
|
|
|
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
|
|
|
Console.set_foreground_color(ForegroundColor.default)
|