42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import logging
|
|
|
|
from ScEpTIC.config.base_config import ScEpTICBaseConfig
|
|
|
|
|
|
class LoggingConfig(ScEpTICBaseConfig):
|
|
"""
|
|
Logger configuration
|
|
"""
|
|
|
|
_config_domain = {
|
|
'enabled': {'class': bool, 'mode': 'set'},
|
|
'log_level': {'class': 'specific', 'values': [logging.CRITICAL, logging.WARNING, logging.INFO, logging.DEBUG], 'mode': 'set'},
|
|
'parser_log_level': {'class': 'specific', 'values': [logging.CRITICAL, logging.WARNING, logging.INFO, logging.DEBUG], 'mode': 'set'},
|
|
'log_section_content': {'class': bool, 'mode': 'set'},
|
|
}
|
|
|
|
def __init__(self, main_config):
|
|
super().__init__(main_config)
|
|
|
|
self.enabled = False
|
|
self.log_level = logging.WARNING
|
|
self.parser_log_level = logging.WARNING
|
|
self.log_section_content = False
|
|
|
|
self._log_config_callback(None, None)
|
|
|
|
self._register_config_callback('enabled', self._log_config_callback)
|
|
|
|
|
|
def _log_config_callback(self, config_name, config_value):
|
|
"""
|
|
Callback that initializes the logger
|
|
:param config_name: the configuration name
|
|
:param config_value: the configuration value
|
|
"""
|
|
for handler in logging.root.handlers[:]:
|
|
logging.root.removeHandler(handler)
|
|
|
|
logging.basicConfig(format='[%(levelname)s - %(asctime)s] %(message)s', level=self.log_level, datefmt='%H:%M:%S')
|
|
logging.getLogger().disabled = not self.enabled
|