diff --git a/app/services/ams/asset_destroyer.rb b/app/services/ams/asset_destroyer.rb index bc3dade8..5ca14ea7 100644 --- a/app/services/ams/asset_destroyer.rb +++ b/app/services/ams/asset_destroyer.rb @@ -5,7 +5,7 @@ class AssetDestroyer def initialize(asset_ids: [], user_email: nil) @asset_ids = Array(asset_ids) @user_email = user_email - @logger = Logger.new(Rails.root.join('tmp', 'imports', 'asset_destroyer.log')) + @logger = setup_logger end def destroy(asset_ids) @@ -117,5 +117,12 @@ def error_rescue(error, object_type, id) msg += ": #{error.message}" unless error.message.empty? logger.error "Error destroying '#{object_type}' for '#{id}'. #{msg}" end + + def setup_logger + logger_path = Rails.root.join('tmp', 'imports', 'asset_destroyer.log') + FileUtils.mkdir_p(logger_path.dirname) + + Logger.new(logger_path) + end end end