[Housekeeping] Improved logging for all executable calls (#244)
* Improved logging for all CLI calls * CAptured more details in logging
This commit is contained in:
parent
bdcb49185a
commit
8d9bd11882
7 changed files with 24 additions and 15 deletions
|
|
@ -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)}
|
||||
|
|
|
|||
|
|
@ -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"])
|
||||
|
|
|
|||
|
|
@ -28,7 +28,10 @@ defmodule Pinchflat.Utils.CliUtils do
|
|||
|
||||
Logger.info("[command_wrapper]: #{command} called with: #{logging_arg_override}")
|
||||
|
||||
System.cmd(wrapper_command, actual_command, passthrough_opts)
|
||||
{output, status} = System.cmd(wrapper_command, actual_command, passthrough_opts)
|
||||
log_cmd_result(command, logging_arg_override, status, output)
|
||||
|
||||
{output, status}
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -71,4 +74,11 @@ defmodule Pinchflat.Utils.CliUtils do
|
|||
defp parse_option(arg, acc) when is_binary(arg) do
|
||||
acc ++ [arg]
|
||||
end
|
||||
|
||||
defp log_cmd_result(command, logging_arg_override, status, output) do
|
||||
log_message = "[command_wrapper]: #{command} called with: #{logging_arg_override} exited: #{status} with: #{output}"
|
||||
log_level = if status == 0, do: :debug, else: :error
|
||||
|
||||
Logger.log(log_level, log_message)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
|||
|
||||
output_filepath = generate_output_filepath(addl_opts)
|
||||
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
||||
user_configured_opts = cookie_file_options() ++ global_options()
|
||||
user_configured_opts = cookie_file_options()
|
||||
# These must stay in exactly this order, hence why I'm giving it its own variable.
|
||||
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts
|
||||
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts ++ global_options()
|
||||
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
||||
|
||||
case CliUtils.wrap_cmd(command, formatted_command_opts, stderr_to_stdout: true) do
|
||||
|
|
@ -71,7 +71,7 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
|||
end
|
||||
|
||||
defp global_options do
|
||||
[:windows_filenames]
|
||||
[:windows_filenames, :quiet]
|
||||
end
|
||||
|
||||
defp cookie_file_options do
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
|||
# `ignore_no_formats_error` is necessary because yt-dlp will error out if
|
||||
# the first video has not released yet (ie: is a premier). We don't care about
|
||||
# available formats since we're just getting the media details
|
||||
command_opts = [:simulate, :skip_download, :ignore_no_formats_error]
|
||||
command_opts = [:simulate, :skip_download, :ignore_no_formats_error, :no_warnings]
|
||||
output_template = YtDlpMedia.indexing_output_template()
|
||||
output_filepath = FilesystemUtils.generate_metadata_tmpfile(:json)
|
||||
file_listener_handler = Keyword.get(addl_opts, :file_listener_handler, false)
|
||||
|
|
|
|||
|
|
@ -87,6 +87,12 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
|||
|
||||
assert String.contains?(output, "--windows-filenames")
|
||||
end
|
||||
|
||||
test "runs quietly" do
|
||||
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||
|
||||
assert String.contains?(output, "--quiet")
|
||||
end
|
||||
end
|
||||
|
||||
describe "version/0" do
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
|||
|
||||
test "it passes the expected default args" do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, opts, ot, _addl_opts ->
|
||||
assert opts == [:simulate, :skip_download, :ignore_no_formats_error]
|
||||
assert opts == [:simulate, :skip_download, :ignore_no_formats_error, :no_warnings]
|
||||
assert ot == Media.indexing_output_template()
|
||||
|
||||
{:ok, ""}
|
||||
|
|
|
|||
Loading…
Reference in a new issue