# Buggy code
def get_logger(
    conf,
    name=None,
    verbose=False,
    fmt="%(process)d %(thread)X %(name)s %(levelname)s %(message)s",
):
    if not conf:
        conf = {}
    if name is None:
        name = "log"
    logger = logging.getLogger(name)
    logger.propagate = False

    syslog_prefix = conf.get("syslog_prefix", "")

    formatter = logging.Formatter(fmt=fmt)
    if syslog_prefix:
        fmt = "%s: %s" % (syslog_prefix, fmt)

    syslog_formatter = logging.Formatter(fmt=fmt)

    if not hasattr(get_logger, "handler4logger"):
        get_logger.handler4logger = {}
    if logger in get_logger.handler4logger:
        logger.removeHandler(get_logger.handler4logger[logger])

    facility = getattr(
        SysLogHandler, conf.get("log_facility", "LOG_LOCAL0"), SysLogHandler.LOG_LOCAL0
    )

    log_address = conf.get("log_address", "/dev/log")
    try:
        handler = SysLogHandler(address=log_address, facility=facility)
    except socket.error as e:
        if e.errno not in [errno.ENOTSOCK, errno.ENOENT]:
            raise e
        handler = SysLogHandler(facility=facility)

    handler.setFormatter(syslog_formatter)
    logger.addHandler(handler)
    get_logger.handler4logger[logger] = handler

    if verbose or hasattr(get_logger, "console_handler4logger"):
        if not hasattr(get_logger, "console_handler4logger"):
            get_logger.console_handler4logger = {}
        if logger in get_logger.console_handler4logger:
            logger.removeHandler(get_logger.console_handler4logger[logger])

        console_handler = logging.StreamHandler(sys.__stderr__)
        console_handler.setFormatter(formatter)
        logger.addHandler(console_handler)
        get_logger.console_handler4logger[logger] = console_handler

    logging_level = getattr(
        logging, conf.get("log_level", "INFO").upper(), logging.INFO
    )
    logger.setLevel(logging_level)

    return logger


# Traceback (ConnectionError)
# openio --oio-ns=VCFR1 directory bootstrap --replicas 3 -v --debug
Starting new HTTP connection (1): 172.17.25.5
"GET /v3.0/VCFR1/conscience/list?type=meta1 HTTP/1.1" 200 376
Computing meta1 prefix mapping...
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
Equilibrating...
META1 Digits = 4
Replicas = 3
Scored positively = 3
Ideal number of prefixes per meta1: 65536
Rebalance moved 0 prefixes
Saving...
Starting new HTTP connection (1): 172.17.25.5
"POST /v3.0/VCFR1/admin/meta0_force HTTP/1.1" 204 0
Assigning rdir services to rawx services...
Starting new HTTP connection (1): 172.17.25.5
"GET /v3.0/VCFR1/conscience/list?type=rawx HTTP/1.1" 200 256
"GET /v3.0/VCFR1/conscience/list?full=1&amp;type=rdir HTTP/1.1" 200 642
Starting new HTTP connection (1): 172.17.25.5
"GET /v3.0/VCFR1/reference/show?acct=_RDIR&amp;ref=172.17.25.7%3A6004&amp;type=rdir HTTP/1.1" 404 59
('Connection aborted.', BadStatusLine("''",))
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/cliff/app.py", line 374, in run_subcommand
result = cmd.run(parsed_args)
File "/usr/lib/python2.7/dist-packages/cliff/command.py", line 54, in run
self.take_action(parsed_args)
File "/usr/lib/python2.7/dist-packages/oio/cli/admin/directory.py", line 60, in take_action
self.app.client_manager.admin.volume.assign_all_rawx()
File "/usr/lib/python2.7/dist-packages/oio/rdir/client.py", line 38, in assign_all_rawx
rdir = self._smart_link_rdir(rawx['addr'], cs, all_rdir)
File "/usr/lib/python2.7/dist-packages/oio/rdir/client.py", line 68, in _smart_link_rdir
polled = cs.poll('rdir', avoid=avoids, known=known)[0]
File "/usr/lib/python2.7/dist-packages/oio/conscience/client.py", line 47, in poll
data=json.dumps(ibody))
File "/usr/lib/python2.7/dist-packages/oio/common/client.py", line 51, in _request
return self._direct_request(method, url, **kwargs)
File "/usr/lib/python2.7/dist-packages/oio/common/client.py", line 37, in _direct_request
**kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 426, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', BadStatusLine("''",))
Exception raised: ('Connection aborted.', BadStatusLine("''",))

# Fixed code
def get_logger(
    conf,
    name=None,
    verbose=False,
    fmt="%(process)d %(thread)X %(name)s %(levelname)s %(message)s",
):
    if not conf:
        conf = {}
    if name is None:
        name = "log"
    logger = logging.getLogger(name)
    logger.propagate = False

    syslog_prefix = conf.get("syslog_prefix", "")

    formatter = logging.Formatter(fmt=fmt)
    if syslog_prefix:
        fmt = "%s: %s" % (syslog_prefix, fmt)

    syslog_formatter = logging.Formatter(fmt=fmt)

    if not hasattr(get_logger, "handler4logger"):
        get_logger.handler4logger = {}
    if logger in get_logger.handler4logger:
        logger.removeHandler(get_logger.handler4logger[logger])

    facility = getattr(
        SysLogHandler, conf.get("log_facility", "LOG_LOCAL0"), SysLogHandler.LOG_LOCAL0
    )

    log_address = conf.get("log_address", "/dev/log")
    try:
        handler = SysLogHandler(address=log_address, facility=facility)
    except socket.error as exc:
        if exc.errno not in [errno.ENOTSOCK, errno.ENOENT]:
            raise exc
        handler = SysLogHandler(facility=facility)

    handler.setFormatter(syslog_formatter)
    logger.addHandler(handler)
    get_logger.handler4logger[logger] = handler

    logging_level = getattr(
        logging, conf.get("log_level", "INFO").upper(), logging.INFO
    )
    if (
        verbose
        or conf.get("is_cli")
        or hasattr(get_logger, "console_handler4logger")
        or logging_level < logging.INFO
    ):
        if not hasattr(get_logger, "console_handler4logger"):
            get_logger.console_handler4logger = {}
        if logger in get_logger.console_handler4logger:
            logger.removeHandler(get_logger.console_handler4logger[logger])

        console_handler = logging.StreamHandler(sys.__stderr__)
        console_handler.setFormatter(formatter)
        logger.addHandler(console_handler)
        get_logger.console_handler4logger[logger] = console_handler

    logger.setLevel(logging_level)

    return logger