import logging


def setup_logging(name, handlers=None, level=None):
    """Set up logging for a named logger.

    Gets and initializes a named logger, ensuring it at least has a
    `logging.NullHandler` attached.

    :param str name:
      Name of the logger.
    :param list handlers:
      A list of `logging.Handler` objects to attach to the logger.
    :param int level:
      Log level to set the logger at.

    :returns: A `logging.Logger` object that can be used to emit log messages.
    """
    handlers = handlers or []
    log = logging.getLogger(name)
    if len(log.handlers) == 0 and not handlers:
        h = logging.NullHandler()
        log.addHandler(h)
    for h in handlers:
        log.addHandler(h)
    if level:
        log.setLevel(level)
    return log