def setup_logger(config=None):
    if config is None:
        return None

    # Do not proceed if logging has not been set up.
    if not (config.has_option('server', 'loglevel') or
            config.has_option('server', 'logfile')):
        return None

    logfile = None
    loglevel = 'NOTSET'

    if config.has_option('server', 'loglevel'):
        loglevel = config.get('server', 'loglevel')

        if loglevel not in LOGLEVELS.keys():
            raise RuntimeError(
                'Invalid server configuration (server.loglevel).')

        if not config.has_option('server', 'logfile'):
            raise RuntimeError(
                'Invalid server configuration (server.loglevel set,\
                but server.logfile missing).')

    if config.has_option('server', 'logfile'):
        if not config.has_option('server', 'loglevel'):
            raise RuntimeError(
                'Invalid server configuration (server.logfile set,\
                but server.loglevel missing).')

        logfile = config.get('server', 'logfile')

    if loglevel != 'NOTSET' and logfile is None:
        raise RuntimeError(
            'Invalid server configuration \
            (server.loglevel set, but server.logfile is not).')

    # Setup logging globally (not only for the pycsw module)
    # based on the parameters passed.
    logging.basicConfig(level=LOGLEVELS[loglevel],
                        filename=logfile,
                        datefmt=TIME_FORMAT,
                        format=MSG_FORMAT)

    LOGGER.info('Logging initialized (level: %s).' % loglevel)

    if loglevel == 'DEBUG':  # turn on CGI debugging
        LOGGER.info('CGI debugging enabled.')
        import cgitb
        cgitb.enable()
Initialize logging facility
dataset/ETHPy150Open geopython/pycsw/pycsw/core/log.py/setup_logger