def validate_config(cls, config_to_validate, level): """Validate and return a LoggingConfig object The plugin logging configuration validates that the handlers/loggers/formatters follow the supported loggers/formatters/handlers that beer-garden supports. :param config_to_validate: A dictionary to validate :param level: A default level to use :return: A valid LoggingConfiguration object """ if not config_to_validate: raise LoggingLoadingError( "No plugin logging configuration specified.") default_level = cls._validate_level( config_to_validate.get("level", level)) cls.logger.debug("Default level: %s" % default_level) handlers = cls._validate_handlers( config_to_validate.get("handlers", {})) formatters = cls._validate_formatters( config_to_validate.get("formatters", {})) loggers = cls._validate_loggers(config_to_validate.get("loggers", {})) return LoggingConfig( level=default_level, handlers=handlers, formatters=formatters, loggers=loggers, )
def logging_config(self): return LoggingConfig( level="INFO", handlers={ "logstash": {}, "stdout": {}, "file": {} }, formatters={"default": { "format": LoggingConfig.DEFAULT_FORMAT }}, loggers=None)
def test_convert_logging_config_default(self): log_config = LoggingConfig(level="level", handlers={}, formatters={}) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") python_config = convert_logging_config(log_config) assert python_config["handlers"] == DEFAULT_HANDLERS assert python_config["formatters"] == DEFAULT_FORMATTERS assert len(w) == 1 assert w[0].category == DeprecationWarning
def test_convert_logging_config(self): handlers = {"hand1": {}, "handler2": {}} formatters = {"formatter1": {}, "formatter2": {}} log_config = LoggingConfig(level="level", handlers=handlers, formatters=formatters) python_config = convert_logging_config(log_config) assert python_config['handlers'] == handlers assert python_config['formatters'] == formatters assert 'root' in python_config assert 'level' in python_config['root'] assert 'handlers' in python_config['root'] assert 'level' == python_config['root']['level'] assert set(handlers) == set(python_config['root']['handlers'])
def test_convert_logging_config(self): handlers = {"hand1": {}, "handler2": {}} formatters = {"formatter1": {}, "formatter2": {}} log_config = LoggingConfig(level="level", handlers=handlers, formatters=formatters) python_config = convert_logging_config(log_config) assert python_config["handlers"] == handlers assert python_config["formatters"] == formatters assert "root" in python_config assert "level" in python_config["root"] assert "handlers" in python_config["root"] assert "level" == python_config["root"]["level"] assert set(handlers) == set(python_config["root"]["handlers"])
def test_convert_logging_config(self): handlers = {"hand1": {}, "handler2": {}} formatters = {"formatter1": {}, "formatter2": {}} log_config = LoggingConfig( level="level", handlers=handlers, formatters=formatters ) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") python_config = convert_logging_config(log_config) assert python_config["handlers"] == handlers assert python_config["formatters"] == formatters assert "root" in python_config assert "level" in python_config["root"] assert "handlers" in python_config["root"] assert "level" == python_config["root"]["level"] assert set(handlers) == set(python_config["root"]["handlers"]) assert len(w) == 1 assert w[0].category == DeprecationWarning
def bg_logging_config(logging_config_dict): """A logging config as a model.""" return LoggingConfig(**logging_config_dict)
def test_names_none(self): config = LoggingConfig(level="INFO") assert config.handler_names is None assert config.formatter_names is None
def test_convert_logging_config_default(self): log_config = LoggingConfig(level="level", handlers={}, formatters={}) python_config = convert_logging_config(log_config) assert python_config['handlers'] == DEFAULT_HANDLERS assert python_config['formatters'] == DEFAULT_FORMATTERS