def get_logger(level=None, name=None, filename=None):
    """
    Create a logger or return the current one if already instantiated.

    Parameters
    ----------
    level : int
        one of the logger.level constants
    name : string
        name of the logger
    filename : string
        name of the log file

    Returns
    -------
    logger.logger
    """

    if level is None:
        level = settings.log_level
    if name is None:
        name = settings.log_name
    if filename is None:
        filename = settings.log_filename

    logger = lg.getLogger(name)

    # if a logger with this name is not already set up
    if not getattr(logger, 'handler_set', None):

        # get today's date and construct a log filename
        todays_date = dt.datetime.today().strftime('%Y_%m_%d')
        log_filename = os.path.join(settings.logs_folder, '{}_{}.log'.format(filename, todays_date))

        # if the logs folder does not already exist, create it
        if not os.path.exists(settings.logs_folder):
            os.makedirs(settings.logs_folder)

        # create file handler and log formatter and set them up
        handler = lg.FileHandler(log_filename, encoding='utf-8')
        formatter = lg.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        logger.setLevel(level)
        logger.handler_set = True

    return logger
def get_logger ( level = None , name = None , filename = None ) : if level is None : level = settings . log_level if name is None : name = settings . log_name if filename is None : filename = settings . log_filename logger = lg . getLogger ( name ) if not getattr ( logger , 'handler_set' , None ) : todays_date = dt . datetime . today ( ) . strftime ( '%Y_%m_%d' ) log_filename = os . path . join ( settings . logs_folder , '{}_{}.log' . format ( filename , todays_date ) ) if not os . path . exists ( settings . logs_folder ) : os . makedirs ( settings . logs_folder ) handler = lg . FileHandler ( log_filename , encoding = 'utf-8' ) formatter = lg . Formatter ( '%(asctime)s %(levelname)s %(name)s %(message)s' ) handler . setFormatter ( formatter ) logger . addHandler ( handler ) logger . setLevel ( level ) logger . handler_set = True return logger
Create a logger or return the current one if already instantiated.

    Parameters
    ----------
    level : int
        one of the logger.level constants
    name : string
        name of the logger
    filename : string
        name of the log file

    Returns
    -------
    logger.logger