Updated validation with loggin

This commit is contained in:
Alexander Werner 2018-11-05 17:01:31 +01:00
parent 8099e2c3ca
commit b534b0e523
2 changed files with 12 additions and 6 deletions

View File

@ -2,12 +2,13 @@ import click
from click_didyoumean import DYMGroup
import click_log
import logging
logger = logging.getLogger(__name__)
click_log.basic_config(logger)
logger = logging.getLogger('carom.cli') # hard coded module name to support directly called module
root_logger = logging.getLogger('')
click_log.basic_config(root_logger)
@click.group(cls=DYMGroup)
@click_log.simple_verbosity_option(logger)
@click_log.simple_verbosity_option(root_logger)
def cli():
pass

View File

@ -1,10 +1,13 @@
import configparser
import logging
from voluptuous import Schema
from voluptuous import Schema, Error
from voluptuous.humanize import validate_with_humanized_errors
from carom.const import CONFIG_FILES, DEFAULT_CONFIG
logger = logging.getLogger(__name__)
_parser = configparser.ConfigParser()
_parser.read_string(DEFAULT_CONFIG)
_parser.read(CONFIG_FILES)
@ -16,6 +19,8 @@ _schema = Schema({
},
})
config = validate_with_humanized_errors(_parser_dict, _schema)
try:
config = validate_with_humanized_errors(_parser_dict, _schema)
except Error as e:
logger.error('Failed to validate the configuration:\n{}'.format(e))
__all__ = ('config', )