Esempio n. 1
0
 def test_levelname_to_integer_knows_all_loglevels(self):
     translated_level = levelname_to_integer('debug')
     self.assertEqual(translated_level, logging.DEBUG)
     translated_level = levelname_to_integer('info')
     self.assertEqual(translated_level, logging.INFO)
     translated_level = levelname_to_integer('warning')
     self.assertEqual(translated_level, logging.WARNING)
     translated_level = levelname_to_integer('error')
     self.assertEqual(translated_level, logging.ERROR)
     translated_level = levelname_to_integer('critical')
     self.assertEqual(translated_level, logging.CRITICAL)
Esempio n. 2
0
 def test_levelname_to_integer_knows_all_loglevels(self):
     translated_level = levelname_to_integer('debug')
     self.assertEqual(translated_level, logging.DEBUG)
     translated_level = levelname_to_integer('info')
     self.assertEqual(translated_level, logging.INFO)
     translated_level = levelname_to_integer('warning')
     self.assertEqual(translated_level, logging.WARNING)
     translated_level = levelname_to_integer('error')
     self.assertEqual(translated_level, logging.ERROR)
     translated_level = levelname_to_integer('critical')
     self.assertEqual(translated_level, logging.CRITICAL)
Esempio n. 3
0
def setup_logging(config, logger_name=''):
    handler_config = config.get('logging_handler')
    logger = logging.getLogger(logger_name)
    if logger.handlers:
        # Was already initialized, nothing to do.
        return logger

    log_level = config.get('log_level', 'info')
    log_level = levelname_to_integer(log_level)
    logger.setLevel(log_level)

    default_config = {
        'module': 'logging.handlers',
        'class': 'SysLogHandler',
        'args': [],
        'kwargs': {'address': '/dev/log'}}
    handler_config = handler_config or default_config
    klass = _get_item_from_module(handler_config['module'],
                                  handler_config['class'])
    args = handler_config.get('args', ())
    kwargs = handler_config.get('kwargs', {})
    try:
        handler = klass(*args, **kwargs)
    except Exception as exc:
        message = ("Could not instantiate logging handler class '{klass}' "
                   "with args '{args}', kwargs '{kwargs}': {exc}")
        raise Exception(message.format(klass=klass, args=args,
                                       kwargs=kwargs, exc=exc))

    log_format = config.get('log_format', 'afp-core: [%(levelname)s] %(message)s')
    formatter = logging.Formatter(log_format)
    handler.setFormatter(formatter)

    logger.addHandler(handler)
    return logger
Esempio n. 4
0
def setup_logging(config, logger_name=''):
    handler_config = config.get('logging_handler')
    logger = logging.getLogger(logger_name)
    if logger.handlers:
        # Was already initialized, nothing to do.
        return logger

    log_level = config.get('log_level', 'info')
    log_level = levelname_to_integer(log_level)
    logger.setLevel(log_level)

    default_config = {
        'module': 'logging.handlers',
        'class': 'SysLogHandler',
        'args': [],
        'kwargs': {
            'address': '/dev/log'
        }
    }
    handler_config = handler_config or default_config
    klass = _get_item_from_module(handler_config['module'],
                                  handler_config['class'])
    args = handler_config.get('args', ())
    kwargs = handler_config.get('kwargs', {})
    try:
        handler = klass(*args, **kwargs)
    except Exception as exc:
        message = ("Could not instantiate logging handler class '{klass}' "
                   "with args '{args}', kwargs '{kwargs}': {exc}")
        raise Exception(
            message.format(klass=klass, args=args, kwargs=kwargs, exc=exc))

    log_format = config.get('log_format',
                            'afp-core: [%(levelname)s] %(message)s')
    formatter = logging.Formatter(log_format)
    handler.setFormatter(formatter)

    logger.addHandler(handler)
    return logger
Esempio n. 5
0
def setup_logging(config):
    handler_config = config.get('logging_handler')
    levelname = config.get('log_level', 'warning')
    logger = logging.getLogger()
    if logger.handlers:
        # Was already initialized, nothing to do.
        return logger
    logger.setLevel(levelname_to_integer(levelname))
    default_config = {
        'module': 'logging.handlers',
        'class': 'SysLogHandler',
        'args': [],
        'kwargs': {'address': '/dev/log'}}
    handler_config = handler_config or default_config
    handler = create_logging_handler(handler_config)

    log_format = config.get('log_format', 'alppaca: [%(levelname)s] %(message)s')
    formatter = logging.Formatter(log_format)
    handler.setFormatter(formatter)

    logger.addHandler(handler)
    return logger
Esempio n. 6
0
 def test_case_insensitive_input_levelname_to_integer(self):
     translated_level = levelname_to_integer('DeBuG')
     self.assertEqual(translated_level, logging.DEBUG)
Esempio n. 7
0
 def test_case_insensitive_input_levelname_to_integer(self):
     translated_level = levelname_to_integer('DeBuG')
     self.assertEqual(translated_level, logging.DEBUG)