Ejemplo n.º 1
0
def __get_logger():
    """ Returns the logger """
    # Instanciate a new logger
    if config_handler.get_logging_option('log_file'):
        logger = LogHandler(
            level=config_handler.get_logging_option('log_level'),
            log_file=config_handler.get_logging_option('log_file'),
            dry_run=config_handler.get_global_option('dry_run'))
    else:
        logger = LogHandler(
            level=config_handler.get_logging_option('log_level'),
            dry_run=config_handler.get_global_option('dry_run'))

    return logger
Ejemplo n.º 2
0
def __get_logger():
    """ Returns the logger """
    # Instanciate a new logger
    if config_handler.get_logging_option('log_file'):
        logger = LogHandler(
            level=config_handler.get_logging_option('log_level'),
            log_file=config_handler.get_logging_option('log_file'),
            dry_run=config_handler.get_global_option('dry_run'))
    else:
        logger = LogHandler(
            level=config_handler.get_logging_option('log_level'),
            dry_run=config_handler.get_global_option('dry_run'))

    return logger
Ejemplo n.º 3
0
def getTableLogger(table_name):
    LOG_CONFIG['handlers']['{}_file'.format(table_name)] = {
        'level': 'DEBUG',
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'formatter': 'standard',
        'filename':
        os.path.expanduser('./logs/{}-table.log'.format(table_name)),
        'when': 'midnight',
        'backupCount': 5
    }
    if config_handler.get_global_option('dry_run'):
        LOG_CONFIG['handlers']['{}_file'.format(
            table_name)]['formatter'] = 'dry-run'
    if config_handler.get_logging_option('log_level'):
        level = config_handler.get_logging_option('log_level').upper()
    else:
        level = 'DEBUG'
    LOG_CONFIG['loggers']['{}_table'.format(table_name)] = {
        'handlers': ['{}_file'.format(table_name)],
        'level': level,
        'propagate': False
    }
    try:
        dictconfig.dictConfig(LOG_CONFIG)
    except ValueError as error:
        print('Error configuring logger: {0}'.format(error))
        sys.exit(1)
    except:
        raise
    return logging.getLogger('{}_table'.format(table_name))
Ejemplo n.º 4
0
        log_file = os.path.expanduser(
            config_handler.get_logging_option('log_file'))
        LOG_CONFIG['handlers']['file'] = {
            'level': 'DEBUG',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'formatter': 'standard',
            'filename': log_file,
            'when': 'midnight',
            'backupCount': 5
        }
        LOG_CONFIG['loggers']['']['handlers'].append('file')
        LOG_CONFIG['loggers']['dynamic-dynamodb']['handlers'].append('file')

    # Configure a custom log level
    if config_handler.get_logging_option('log_level'):
        LOG_CONFIG['handlers']['console']['level'] = \
            config_handler.get_logging_option('log_level').upper()
        if 'file' in LOG_CONFIG['handlers']:
            LOG_CONFIG['handlers']['file']['level'] = \
                config_handler.get_logging_option('log_level').upper()

    # Add dry-run to the formatter if in dry-run mode
    if config_handler.get_global_option('dry_run'):
        LOG_CONFIG['handlers']['console']['formatter'] = 'dry-run'
        if 'file' in LOG_CONFIG['handlers']:
            LOG_CONFIG['handlers']['file']['formatter'] = 'dry-run'

    dictconfig.dictConfig(LOG_CONFIG)

LOGGER = logging.getLogger('dynamic-dynamodb')