def setup_logger(project, cfg):

    if _loggers.get(project):
        return

    logger = getLogger(None)

    # Set logging level.
    level = LOG_LEVELS.get(cfg.dfa_log.log_level.lower(), logging.WARNING)
    logger.setLevel(level)

    # Set default log levels for specified modules.
    def_log_levels = cfg.dfa_log.default_log_levels
    for dll in def_log_levels.split(','):
        mod, sep, lvl = dll.partition('=')
        level = LOG_LEVELS.get(lvl.lower(), logging.WARNING)
        logging.getLogger(mod).setLevel(level)

    # Set log file path name.
    log_dir = cfg.dfa_log.log_dir
    log_file = cfg.dfa_log.log_file
    if log_dir and log_file:
        try:
            if not os.path.exists(log_dir):
                os.makedirs(log_dir)
        except __HOLE__:
            pass
        else:
            log_file_path = os.path.join(log_dir, log_file)
            handler = log_hdlr.TimedRotatingFileHandler(log_file_path,
                                                        when=DAYS,
                                                        interval=1)
    else:
        handler = logging.StreamHandler(sys.stdout)

    if cfg.dfa_log.use_syslog.lower() == 'true':
        log_fac = cfg.dfa_log.syslog_log_facility
        facility = getattr(log_hdlr.SysLogHandler, log_fac, None)
        handler = log_hdlr.SysLogHandler(address='/dev/log',
                                         facility=facility)

    # Setting log format.
    log_format = cfg.dfa_log.log_format
    date_fowrmat = cfg.dfa_log.log_date_format
    formatter = logging.Formatter(fmt=log_format, datefmt=date_fowrmat)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    _loggers[project] = logger
dataset/ETHPy150Open openstack/networking-cisco/networking_cisco/apps/saf/common/dfa_logger.py/setup_logger