def setup_logging(level, logger_name=None, handler=None, log_formatter=None):
    """
    levels:
         1 - hardcode DEBUG ;)
        10 - DEBUG
        20 - INFO
        30 - WARNING
        40 - ERROR
        50 - CRITICAL/FATAL
        99 - nearly off
       100 - complete off
    """
    root_logger = logging.getLogger()

    if logger_name is None:
        logger = root_logger
        root_logger.info("Set %i level to root logger", level)
    else:
        logger = logging.getLogger(logger_name)
        root_logger.info("Set %i level to logger %r", level, logger_name)

    if level == 100:
        # Remove all existing handlers and set only NullHandler():
        set_handler(logger, logging.NullHandler())
        logger.disabled = True
        return

    logger.setLevel(level=level)

    if log_formatter is None:
        log_formatter = "%(relativeCreated)-5d %(levelname)8s %(module)13s %(lineno)d %(message)s"
    formatter = logging.Formatter(log_formatter)

    if handler is None:
        handler = logging.StreamHandler()
    handler.setFormatter(formatter)

    if hasattr(handler, "baseFilename"):
        root_logger.debug("Log to file: %s (%s)", handler.baseFilename, repr(handler))
    else:
        root_logger.debug("Log to handler: %s", repr(handler))

    # Remove all existing handlers and set only the given handler:
    set_handler(logger, handler)

    log.log(level, "Set logging to level %i %s", level, logging.getLevelName(level))