pypet/pypetlogging.py
def _change_logging_kwargs(kwargs):
    """ Helper function to turn the simple logging kwargs into a `log_config`."""
    log_levels = kwargs.pop('log_level', None)
    log_folder = kwargs.pop('log_folder', 'logs')
    logger_names = kwargs.pop('logger_names', '')
    if log_levels is None:
        log_levels = kwargs.pop('log_levels', logging.INFO)
    log_multiproc = kwargs.pop('log_multiproc', True)

    if not isinstance(logger_names, (tuple, list)):
        logger_names = [logger_names]
    if not isinstance(log_levels, (tuple, list)):
        log_levels = [log_levels]
    if len(log_levels) == 1:
        log_levels = [log_levels[0] for _ in logger_names]

    # We don't want to manipulate the original dictionary
    dictionary = copy.deepcopy(LOGGING_DICT)
    prefixes = ['']
    if not log_multiproc:
        for key in list(dictionary.keys()):
            if key.startswith('multiproc_'):
                del dictionary[key]
    else:
        prefixes.append('multiproc_')

    # Add all handlers to all loggers
    for prefix in prefixes:
        for handler_dict in dictionary[prefix + 'handlers'].values():
            if 'filename' in handler_dict:
                filename = os.path.join(log_folder, handler_dict['filename'])
                filename = os.path.normpath(filename)
                handler_dict['filename'] = filename
        dictionary[prefix + 'loggers'] = {}
        logger_dict = dictionary[prefix + 'loggers']
        for idx, logger_name in enumerate(logger_names):
            logger_dict[logger_name] = {
                'level': log_levels[idx],
                'handlers': list(dictionary[prefix + 'handlers'].keys())
            }

    kwargs['log_config'] = dictionary
def _change_logging_kwargs(kwargs):
    log_levels = kwargs.pop('log_level', None)
    log_folder = kwargs.pop('log_folder', 'logs')
    logger_names = kwargs.pop('logger_names', '')
    if log_levels is None:
        log_levels = kwargs.pop('log_levels', logging.INFO)
    log_multiproc = kwargs.pop('log_multiproc', True)

    if not isinstance(logger_names, (tuple, list)):
        logger_names = [logger_names]
    if not isinstance(log_levels, (tuple, list)):
        log_levels = [log_levels]
    if len(log_levels) == 1:
        log_levels = [log_levels[0] for _ in logger_names]

    # We don't want to manipulate the original dictionary
    dictionary = copy.deepcopy(LOGGING_DICT)
    prefixes = ['']
    if not log_multiproc:
        for key in list(dictionary.keys()):
            if key.startswith('multiproc_'):
                del dictionary[key]
    else:
        prefixes.append('multiproc_')

    # Add all handlers to all loggers
    for prefix in prefixes:
        for handler_dict in dictionary[prefix + 'handlers'].values():
            if 'filename' in handler_dict:
                filename = os.path.join(log_folder, handler_dict['filename'])
                filename = os.path.normpath(filename)
                handler_dict['filename'] = filename
        dictionary[prefix + 'loggers'] = {}
        logger_dict = dictionary[prefix + 'loggers']
        for idx, logger_name in enumerate(logger_names):
            logger_dict[logger_name] = {
                'level': log_levels[idx],
                'handlers': list(dictionary[prefix + 'handlers'].keys())
            }

    kwargs['log_config'] = dictionary
def _change_logging_kwargs ( kwargs ) : log_levels = kwargs . pop ( 'log_level' , None ) log_folder = kwargs . pop ( 'log_folder' , 'logs' ) logger_names = kwargs . pop ( 'logger_names' , '' ) if log_levels is None : log_levels = kwargs . pop ( 'log_levels' , logging . INFO ) log_multiproc = kwargs . pop ( 'log_multiproc' , True ) if not isinstance ( logger_names , ( tuple , list ) ) : logger_names = [ logger_names ] if not isinstance ( log_levels , ( tuple , list ) ) : log_levels = [ log_levels ] if len ( log_levels ) == 1 : log_levels = [ log_levels [ 0 ] for _ in logger_names ] # We don't want to manipulate the original dictionary dictionary = copy . deepcopy ( LOGGING_DICT ) prefixes = [ '' ] if not log_multiproc : for key in list ( dictionary . keys ( ) ) : if key . startswith ( 'multiproc_' ) : del dictionary [ key ] else : prefixes . append ( 'multiproc_' ) # Add all handlers to all loggers for prefix in prefixes : for handler_dict in dictionary [ prefix + 'handlers' ] . values ( ) : if 'filename' in handler_dict : filename = os . path . join ( log_folder , handler_dict [ 'filename' ] ) filename = os . path . normpath ( filename ) handler_dict [ 'filename' ] = filename dictionary [ prefix + 'loggers' ] = { } logger_dict = dictionary [ prefix + 'loggers' ] for idx , logger_name in enumerate ( logger_names ) : logger_dict [ logger_name ] = { 'level' : log_levels [ idx ] , 'handlers' : list ( dictionary [ prefix + 'handlers' ] . keys ( ) ) } kwargs [ 'log_config' ] = dictionary
Helper function to turn the simple logging kwargs into a `log_config`.
Helper function to turn the simple logging kwargs into a log_config .