import logging, coloredlogs

def logsetup(filename, format, loglevel):
    logging.basicConfig(filename=filename, level=loglevel)
    root = logging.getLogger()

    sh = logging.StreamHandler()
    # sh.setLevel(loglevel)

    formatter = coloredlogs.ColoredFormatter(fmt=format, field_styles={
        "hostname": {"color": "blue"},
        "programname": {"color": "cyan"},
        "name": {"color": "red"},
        "levelname": {"color": "magenta"},
        "asctime": {"color": "cyan"}
    })

    fh = root.handlers[0]
    fh.setFormatter(formatter)

    sh.setFormatter(formatter)
    root.addHandler(sh)

    return logging.getLogger("bea")
