def setup_logging():
    """
    Sets up the internal logging mechanism, i.e., it creates the :py:attr:`console_handler`, sets
    its formatting, and mounts on on the main ``"law"`` logger. It also sets the levels of all
    loggers that are given in the law config.
    """
    global console_handler

    # make sure logging is setup only once
    if console_handler:
        return

    # set the handler of the law root logger
    console_handler = logging.StreamHandler()
    console_handler.setFormatter(LogFormatter())
    logging.getLogger("law").addHandler(console_handler)

    # set levels for all loggers
    for name, level in Config.instance().items("logging"):
        level = level.upper()
        if hasattr(logging, level):
            logger = logging.getLogger(name)
            logger.setLevel(getattr(logging, level))
            logger.debug("registered logger with level '{}'".format(level))