From 71683a0dfa7f99f41d294d10c14c868ca81fa779 Mon Sep 17 00:00:00 2001 From: Benjamin Kiah Stroud <32469930+bkiahstroud@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:06:13 -0700 Subject: [PATCH] ensure path to logger exists This should fix specs that are failing in CI --- app/services/ams/asset_destroyer.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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