From cfa3dd95bf0863a88f3a30dec4671031b97ba289 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Wed, 15 May 2024 12:34:25 -0700 Subject: [PATCH] Improved logging for all CLI calls --- .../lifecycle/notifications/command_runner.ex | 1 - .../lifecycle/user_scripts/command_runner.ex | 10 ++-------- lib/pinchflat/utils/cli_utils.ex | 12 +++++++++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/pinchflat/lifecycle/notifications/command_runner.ex b/lib/pinchflat/lifecycle/notifications/command_runner.ex index a8e08a5..77d43ff 100644 --- a/lib/pinchflat/lifecycle/notifications/command_runner.ex +++ b/lib/pinchflat/lifecycle/notifications/command_runner.ex @@ -29,7 +29,6 @@ defmodule Pinchflat.Lifecycle.Notifications.CommandRunner do parsed_opts = CliUtils.parse_options(default_opts ++ command_opts) {output, exit_code} = CliUtils.wrap_cmd(backend_executable(), parsed_opts ++ endpoints) - Logger.info("[apprise] response: #{output}") case exit_code do 0 -> {:ok, String.trim(output)} diff --git a/lib/pinchflat/lifecycle/user_scripts/command_runner.ex b/lib/pinchflat/lifecycle/user_scripts/command_runner.ex index b346bbe..8436c05 100644 --- a/lib/pinchflat/lifecycle/user_scripts/command_runner.ex +++ b/lib/pinchflat/lifecycle/user_scripts/command_runner.ex @@ -39,7 +39,7 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do {:ok, executable_path} -> {:ok, encoded_data} = Phoenix.json_library().encode(encodable_data) - {output, exit_code} = + {_output, _exit_code} = CliUtils.wrap_cmd( executable_path, [to_string(event_type), encoded_data], @@ -47,7 +47,7 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do logging_arg_override: "[suppressed]" ) - handle_output(output, exit_code) + :ok end end @@ -55,12 +55,6 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do raise ArgumentError, "Invalid event type: #{inspect(event_type)}" end - defp handle_output(output, exit_code) do - Logger.debug("Custom lifecycle script exit code: #{exit_code} with output: #{output}") - - :ok - end - defp backend_executable do base_dir = Application.get_env(:pinchflat, :extras_directory) filepath = Path.join([base_dir, "user-scripts", "lifecycle"]) diff --git a/lib/pinchflat/utils/cli_utils.ex b/lib/pinchflat/utils/cli_utils.ex index 1b9c7b9..72854cb 100644 --- a/lib/pinchflat/utils/cli_utils.ex +++ b/lib/pinchflat/utils/cli_utils.ex @@ -28,7 +28,17 @@ defmodule Pinchflat.Utils.CliUtils do Logger.info("[command_wrapper]: #{command} called with: #{logging_arg_override}") - System.cmd(wrapper_command, actual_command, passthrough_opts) + case System.cmd(wrapper_command, actual_command, passthrough_opts) do + {output, 0 = status} -> + Logger.debug("[command_wrapper]: #{command} called with: #{logging_arg_override} returned: #{status}") + + {output, status} + + {output, status} -> + Logger.error("[command_wrapper]: #{command} called with: #{logging_arg_override} returned: #{status}") + + {output, status} + end end @doc """