def setup_logger(logger, stream, filename=None, fmt=None):
    """
    Set up a logger (if no handlers exist) for console output,
    and file 'tee' output if desired.
    """
    if len(logger.handlers) < 1:
        console = logging.StreamHandler(stream)
        console.setLevel(logging.DEBUG)
        console.setFormatter(logging.Formatter(fmt))
        logger.addHandler(console)
        logger.setLevel(logging.DEBUG)
        logger.propagate = False

        if filename:
            outfile = logging.FileHandler(filename)
            outfile.setLevel(logging.INFO)
            outfile.setFormatter(logging.Formatter("%(asctime)s " + (fmt if fmt else '%(message)s')))
            logger.addHandler(outfile)
Set up a logger (if no handlers exist) for console output,
    and file 'tee' output if desired.