def configure_logger(loglevel=2, quiet=False, logdir=None):
    "Creates the logger instance and adds handlers plus formatting."
    logger = logging.getLogger()

    # Set the loglevel.
    if loglevel > 3:
        loglevel = 3  # Cap at 3 to avoid index errors.
    levels = [logging.ERROR, logging.WARN, logging.INFO, logging.DEBUG]
    logger.setLevel(levels[loglevel])

    logformat = "%(asctime)-14s %(levelname)-8s %(name)-8s %(message)s"

    formatter = logging.Formatter(logformat, "%Y-%m-%d %H:%M:%S")

    if not quiet:
        console_handler = logging.StreamHandler(sys.stdout)
        console_handler.setFormatter(formatter)
        logger.addHandler(console_handler)
        logger.debug("Added logging console handler.")
        logger.info("Loglevel is {}.".format(levels[loglevel]))
    if logdir:
        try:
            logfile = os.path.join(logdir, "demimove.log")
            file_handler = logging.FileHandler(logfile)
            file_handler.setFormatter(formatter)
            logger.addHandler(file_handler)
            logger.debug("Added logging file handler: {}.".format(logfile))
        except __HOLE__:
            logger.error("Could not attach file handler.")
dataset/ETHPy150Open mikar/demimove/demimove/helpers.py/configure_logger