Improved logging for all CLI calls
This commit is contained in:
parent
bdcb49185a
commit
cfa3dd95bf
3 changed files with 13 additions and 10 deletions
|
|
@ -29,7 +29,6 @@ defmodule Pinchflat.Lifecycle.Notifications.CommandRunner do
|
||||||
parsed_opts = CliUtils.parse_options(default_opts ++ command_opts)
|
parsed_opts = CliUtils.parse_options(default_opts ++ command_opts)
|
||||||
|
|
||||||
{output, exit_code} = CliUtils.wrap_cmd(backend_executable(), parsed_opts ++ endpoints)
|
{output, exit_code} = CliUtils.wrap_cmd(backend_executable(), parsed_opts ++ endpoints)
|
||||||
Logger.info("[apprise] response: #{output}")
|
|
||||||
|
|
||||||
case exit_code do
|
case exit_code do
|
||||||
0 -> {:ok, String.trim(output)}
|
0 -> {:ok, String.trim(output)}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do
|
||||||
{:ok, executable_path} ->
|
{:ok, executable_path} ->
|
||||||
{:ok, encoded_data} = Phoenix.json_library().encode(encodable_data)
|
{:ok, encoded_data} = Phoenix.json_library().encode(encodable_data)
|
||||||
|
|
||||||
{output, exit_code} =
|
{_output, _exit_code} =
|
||||||
CliUtils.wrap_cmd(
|
CliUtils.wrap_cmd(
|
||||||
executable_path,
|
executable_path,
|
||||||
[to_string(event_type), encoded_data],
|
[to_string(event_type), encoded_data],
|
||||||
|
|
@ -47,7 +47,7 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do
|
||||||
logging_arg_override: "[suppressed]"
|
logging_arg_override: "[suppressed]"
|
||||||
)
|
)
|
||||||
|
|
||||||
handle_output(output, exit_code)
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -55,12 +55,6 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do
|
||||||
raise ArgumentError, "Invalid event type: #{inspect(event_type)}"
|
raise ArgumentError, "Invalid event type: #{inspect(event_type)}"
|
||||||
end
|
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
|
defp backend_executable do
|
||||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||||
filepath = Path.join([base_dir, "user-scripts", "lifecycle"])
|
filepath = Path.join([base_dir, "user-scripts", "lifecycle"])
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,17 @@ defmodule Pinchflat.Utils.CliUtils do
|
||||||
|
|
||||||
Logger.info("[command_wrapper]: #{command} called with: #{logging_arg_override}")
|
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
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue