示例#1
0
 def logging_config(self, name):
     if name != 'main':
         raise KeyError
     parser = SafeConfigParser()
     parser.read(self.path)
     for section_name in ('loggers', 'handlers', 'formatters'):
         if not parser.has_section(section_name):
             raise KeyError
     loggers = convert_loggers(parser)
     handlers = convert_handlers(parser)
     formatters = convert_formatters(parser)
     return combine(loggers, handlers, formatters)
def test_combined(ini_cp):
    loggers = convert_loggers(ini_cp)
    handlers = convert_handlers(ini_cp)
    formatters = convert_formatters(ini_cp)
    root_logger = loggers['root']
    other_loggers = dict([(k, v) for k, v in loggers.items() if k != 'root'])
    expected = {
        'version': 1,
        'root': root_logger,
        'loggers': other_loggers,
        'handlers': handlers,
        'formatters': formatters,
    }
    actual = combine(loggers, handlers, formatters)
    assert expected == actual
def test_handlers(ini_cp):
    # py26 names it 'strm' for unknown reasons
    stream_key_name = 'stream' if (sys.version_info[0] > 2 or sys.version_info[1] > 6) else 'strm'
    expected = {
        'console': {
            'class': 'logging.StreamHandler',
            'level': 'DEBUG',
            'formatter': 'simple',
            stream_key_name: sys.stdout,
        },
        'syslog': {
            'class': 'logging.handlers.SysLogHandler',
            'level': 'WARNING',
            'formatter': 'complicated',
        }
    }
    actual = convert_handlers(ini_cp)
    assert expected == actual