def init_app(self, app, distributed_storage): location = app.config.get('LOG_ARCHIVE_LOCATION') path = app.config.get('LOG_ARCHIVE_PATH', None) handler_name = 'web.logarchive' log_archive = DelegateUserfiles(app, distributed_storage, location, path, handler_name=handler_name) # register extension with app app.extensions = getattr(app, 'extensions', {}) app.extensions['log_archive'] = log_archive return log_archive
def _perform_archiving(self, cutoff_date): assert datetime.now() - cutoff_date >= MINIMUM_LOGS_AGE_FOR_ARCHIVE archived_files = [] save_location = SAVE_LOCATION if not save_location: # Pick the *same* save location for all instances. This is a fallback if # a location was not configured. save_location = storage.locations[0] log_archive = DelegateUserfiles(app, storage, save_location, SAVE_PATH) for log_rotation_context in logs_model.yield_log_rotation_context( cutoff_date, MIN_LOGS_PER_ROTATION): with log_rotation_context as context: for logs, filename in context.yield_logs_batch(): formatted_logs = [log_dict(log) for log in logs] logger.debug("Archiving logs rotation %s", filename) _write_logs(filename, formatted_logs, log_archive) logger.debug("Finished archiving logs to %s", filename) archived_files.append(filename) return archived_files
def test_filepath(prefix, path, expected): userfiles = DelegateUserfiles(None, None, 'local_us', prefix) assert userfiles.get_file_id_path(path) == expected