Add `LOG_SILENCE` env for local dev, remove less helpful debug/warn logs (Elixir kind, not FarmBot kind)

pull/1168/head
Rick Carlino 2020-03-06 09:45:12 -06:00
parent 0058d1b01e
commit 1f26485f88
12 changed files with 36 additions and 40 deletions

View File

@ -189,7 +189,6 @@ defmodule FarmbotCore.Asset.Command do
# Catch-all use case: # Catch-all use case:
def update(asset_kind, id, params) do def update(asset_kind, id, params) do
Logger.warn("AssetCommand needs implementation: #{asset_kind}")
mod = as_module!(asset_kind) mod = as_module!(asset_kind)
case Repo.get_by(mod, id: id) do case Repo.get_by(mod, id: id) do

View File

@ -94,7 +94,6 @@ defmodule FarmbotCore.AssetMonitor do
Map.put(sub_state, id, updated_at) Map.put(sub_state, id, updated_at)
is_nil(sub_state[id]) -> is_nil(sub_state[id]) ->
Logger.debug("#{inspect(kind)} #{id} needs to be started")
asset = Repo.preload(asset, AssetWorker.preload(asset)) asset = Repo.preload(asset, AssetWorker.preload(asset))
:ok = AssetSupervisor.start_child(asset) |> assert_result!(asset) :ok = AssetSupervisor.start_child(asset) |> assert_result!(asset)
Map.put(sub_state, id, updated_at) Map.put(sub_state, id, updated_at)

View File

@ -13,7 +13,8 @@ defmodule FarmbotCore.Leds.StubHandler do
def white5(status), do: do_debug(:white, status) def white5(status), do: do_debug(:white, status)
defp do_debug(color, status) do defp do_debug(color, status) do
msg = [IO.ANSI.reset(), "LED STATUS: ", unless System.get_env("LOG_SILENCE") do
msg = [IO.ANSI.reset(), "LED STATUS: ",
apply(IO.ANSI, color, []), apply(IO.ANSI, color, []),
status_in(status), status_in(status),
to_string(color), to_string(color),
@ -22,7 +23,8 @@ defmodule FarmbotCore.Leds.StubHandler do
status_out(status), status_out(status),
IO.ANSI.reset() IO.ANSI.reset()
] ]
IO.puts(msg) IO.puts(msg)
end
end end
defp status_in(:slow_blink), do: IO.ANSI.blink_slow() defp status_in(:slow_blink), do: IO.ANSI.blink_slow()

View File

@ -23,7 +23,9 @@ defmodule FarmbotCore.LogExecutor do
do: level, do: level,
else: :info else: :info
Elixir.Logger.bare_log(logger_level, log, logger_meta) unless System.get_env("LOG_SILENCE") do
Elixir.Logger.bare_log(logger_level, log, logger_meta)
end
log log
end end
end end

View File

@ -1,6 +1,6 @@
{ {
"coverage_options": { "coverage_options": {
"treat_no_relevant_lines_as_covered": true, "treat_no_relevant_lines_as_covered": true,
"minimum_coverage": 35 "minimum_coverage": 39
} }
} }

View File

@ -35,7 +35,7 @@ defmodule FarmbotExt.AMQP.AutoSyncChannel do
Tool Tool
) )
# Sync messgaes about these assets # Sync messgages about these assets
# should not be cached. They need to be applied # should not be cached. They need to be applied
# in real time. # in real time.
@no_cache_kinds ~w( @no_cache_kinds ~w(
@ -136,11 +136,8 @@ defmodule FarmbotExt.AMQP.AutoSyncChannel do
id = data["id"] || String.to_integer(id_str) id = data["id"] || String.to_integer(id_str)
_ = handle_asset(asset_kind, id, body) _ = handle_asset(asset_kind, id, body)
["bot", ^device, "sync", asset_kind, _id_str] -> _ -> ""
Logger.warn("Unknown syncable asset: #{asset_kind}") # Logger.info("ignoring route: #{key}")
_ ->
Logger.info("ignoring route: #{key}")
end end
:ok = ConnectionWorker.rpc_reply(chan, device, label) :ok = ConnectionWorker.rpc_reply(chan, device, label)

View File

@ -66,7 +66,6 @@ defmodule FarmbotExt.API.EagerLoader do
* a remote `id` field. * a remote `id` field.
""" """
def cache(%Changeset{data: %module{}} = changeset) do def cache(%Changeset{data: %module{}} = changeset) do
Logger.info("Caching #{inspect(changeset)}")
id = Changeset.get_field(changeset, :id) id = Changeset.get_field(changeset, :id)
updated_at = Changeset.get_field(changeset, :updated_at) updated_at = Changeset.get_field(changeset, :updated_at)
id || change_error(changeset, "Can't cache a changeset with no :id attribute") id || change_error(changeset, "Can't cache a changeset with no :id attribute")

View File

@ -51,8 +51,6 @@ defmodule FarmbotExt.Bootstrap do
end end
def try_auth(email, server, password, _secret) do def try_auth(email, server, password, _secret) do
Logger.debug("using password to auth")
with {:ok, tkn} <- Authorization.authorize_with_password(email, password, server), with {:ok, tkn} <- Authorization.authorize_with_password(email, password, server),
_ <- update_config_value(:string, "authorization", "token", tkn), _ <- update_config_value(:string, "authorization", "token", tkn),
{:ok, pid} <- Supervisor.start_child(FarmbotExt, Bootstrap.Supervisor) do {:ok, pid} <- Supervisor.start_child(FarmbotExt, Bootstrap.Supervisor) do

View File

@ -105,7 +105,7 @@ defmodule AutoSyncChannelTest do
}) })
send(pid, {:basic_deliver, payload, %{routing_key: "WRONG!"}}) send(pid, {:basic_deliver, payload, %{routing_key: "WRONG!"}})
assert_receive {:rpc_reply_called, %{fake: :chan}, "device_15", "xyz"} assert_receive {:rpc_reply_called, %{fake: :chan}, "device_15", "xyz"}, 1000
end end
test "wont autosync unknown assets" do test "wont autosync unknown assets" do
@ -121,7 +121,7 @@ defmodule AutoSyncChannelTest do
}) })
send(pid, {:basic_deliver, payload, %{routing_key: "bot.device_15.sync.SavedGarden.999"}}) send(pid, {:basic_deliver, payload, %{routing_key: "bot.device_15.sync.SavedGarden.999"}})
assert_receive {:rpc_reply_called, %{fake: :chan}, "device_15", "xyz"} assert_receive {:rpc_reply_called, %{fake: :chan}, "device_15", "xyz"}, 1000
end end
test "ignores asset deletion when auto_sync is off" do test "ignores asset deletion when auto_sync is off" do
@ -136,9 +136,10 @@ defmodule AutoSyncChannelTest do
end) end)
send(pid, {:basic_deliver, payload, %{routing_key: key}}) send(pid, {:basic_deliver, payload, %{routing_key: key}})
assert_receive :called_auto_sync? assert_receive :called_auto_sync?, 1200
end end
@tag :blinky
test "handles Device assets" do test "handles Device assets" do
%{pid: pid} = under_normal_conditions() %{pid: pid} = under_normal_conditions()
test_pid = self() test_pid = self()
@ -152,7 +153,7 @@ defmodule AutoSyncChannelTest do
end) end)
send(pid, {:basic_deliver, payload, %{routing_key: key}}) send(pid, {:basic_deliver, payload, %{routing_key: key}})
assert_receive {:update_called, "Device", 999, %{}} assert_receive {:update_called, "Device", 999, %{}}, 1200
end end
def simple_asset_test_singleton(module_name) do def simple_asset_test_singleton(module_name) do
@ -175,9 +176,10 @@ defmodule AutoSyncChannelTest do
send(pid, {:basic_deliver, payload, %{routing_key: key}}) send(pid, {:basic_deliver, payload, %{routing_key: key}})
assert_receive {:update_called, ^module_name, 999, %{"foo" => "bar"}} assert_receive {:update_called, ^module_name, 999, %{"foo" => "bar"}}, 1000
end end
@tag :blinky
test "handles auto_sync of 'no_cache' when auto_sync is false" do test "handles auto_sync of 'no_cache' when auto_sync is false" do
test_pid = self() test_pid = self()
%{pid: pid} = under_normal_conditions() %{pid: pid} = under_normal_conditions()
@ -196,8 +198,8 @@ defmodule AutoSyncChannelTest do
end) end)
send(pid, {:basic_deliver, payload, %{routing_key: key}}) send(pid, {:basic_deliver, payload, %{routing_key: key}})
assert_receive :called_auto_sync? assert_receive :called_auto_sync?, 1200
assert_receive {:update_called, "FbosConfig", 999, %{"foo" => "bar"}} assert_receive {:update_called, "FbosConfig", 999, %{"foo" => "bar"}}, 1200
end end
test "auto_sync disabled, resource not in @cache_kinds" do test "auto_sync disabled, resource not in @cache_kinds" do
@ -232,6 +234,6 @@ defmodule AutoSyncChannelTest do
send(pid, {:basic_deliver, payload, %{routing_key: key}}) send(pid, {:basic_deliver, payload, %{routing_key: key}})
assert_receive {:update_called, ^module_name, 999, %{"foo" => "bar"}} assert_receive {:update_called, ^module_name, 999, %{"foo" => "bar"}}, 3000
end end
end end

View File

@ -8,9 +8,16 @@ defmodule FarmbotExt.AMQP.BotStateChannelTest do
setup :verify_on_exit! setup :verify_on_exit!
setup :set_mimic_global setup :set_mimic_global
test "read_status" do defmodule FakeState do
# {:ok, pid} = GenServer.start_link(BotStateChannel, [jwt: %{}]) defstruct conn: %{fake: :conn}, chan: "fake_chan_", jwt: "fake_jwt_", cache: %{fake: :cache}
# expect(BotState, :fetch, 1, fn -> %{} end) end
# BotStateChannel.read_status(pid)
test "terminate" do
expected = "Disconnected from BotState channel: \"foo\""
expect(AMQP.Channel, :close, 1, fn "fake_chan_" -> :ok end)
expect(FarmbotCore.LogExecutor, :execute, 1, fn log ->
assert log.message == expected
end)
FarmbotExt.AMQP.BotStateChannel.terminate("foo", %FakeState{})
end end
end end

View File

@ -6,7 +6,8 @@ Mimic.copy(FarmbotCore.Asset.Command)
Mimic.copy(FarmbotCore.Asset.Query) Mimic.copy(FarmbotCore.Asset.Query)
Mimic.copy(FarmbotExt.AMQP.ConnectionWorker) Mimic.copy(FarmbotExt.AMQP.ConnectionWorker)
Mimic.copy(FarmbotExt.API) Mimic.copy(FarmbotExt.API)
Mimic.copy(AMQP.Channel)
Mimic.copy(FarmbotCore.LogExecutor)
if timeout do if timeout do
ExUnit.start(assert_receive_timeout: String.to_integer(timeout)) ExUnit.start(assert_receive_timeout: String.to_integer(timeout))
else else

View File

@ -300,20 +300,10 @@ defmodule FarmbotFirmware do
name: state.reset name: state.reset
) do ) do
{:ok, pid} -> {:ok, pid} ->
Logger.debug(
"Firmware reset #{state.reset} started. #{
inspect(state.transport_args)
}"
)
{:noreply, %{state | reset_pid: pid}} {:noreply, %{state | reset_pid: pid}}
# TODO(Rick): I have no idea what's going on here. # TODO(Rick): I have no idea what's going on here.
{:error, {:already_started, pid}} -> {:error, {:already_started, pid}} ->
Logger.debug(
"Firmware reset complete. #{inspect(state.transport_args)}"
)
{:noreply, %{state | reset_pid: pid}} {:noreply, %{state | reset_pid: pid}}
error -> error ->