Improved logging for all CLI calls

This commit is contained in:
Kieran Eglin 2024-05-15 12:34:25 -07:00
parent bdcb49185a
commit cfa3dd95bf
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 13 additions and 10 deletions

View file

@ -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)}

View file

@ -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"])

View file

@ -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 """