Add `LOG_SILENCE` env for local dev, remove less helpful debug/warn logs (Elixir kind, not FarmBot kind)
parent
0058d1b01e
commit
1f26485f88
|
@ -189,7 +189,6 @@ defmodule FarmbotCore.Asset.Command do
|
|||
|
||||
# Catch-all use case:
|
||||
def update(asset_kind, id, params) do
|
||||
Logger.warn("AssetCommand needs implementation: #{asset_kind}")
|
||||
mod = as_module!(asset_kind)
|
||||
|
||||
case Repo.get_by(mod, id: id) do
|
||||
|
|
|
@ -94,7 +94,6 @@ defmodule FarmbotCore.AssetMonitor do
|
|||
Map.put(sub_state, id, updated_at)
|
||||
|
||||
is_nil(sub_state[id]) ->
|
||||
Logger.debug("#{inspect(kind)} #{id} needs to be started")
|
||||
asset = Repo.preload(asset, AssetWorker.preload(asset))
|
||||
:ok = AssetSupervisor.start_child(asset) |> assert_result!(asset)
|
||||
Map.put(sub_state, id, updated_at)
|
||||
|
|
|
@ -13,7 +13,8 @@ defmodule FarmbotCore.Leds.StubHandler do
|
|||
def white5(status), do: do_debug(:white, status)
|
||||
|
||||
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, []),
|
||||
status_in(status),
|
||||
to_string(color),
|
||||
|
@ -22,7 +23,8 @@ defmodule FarmbotCore.Leds.StubHandler do
|
|||
status_out(status),
|
||||
IO.ANSI.reset()
|
||||
]
|
||||
IO.puts(msg)
|
||||
IO.puts(msg)
|
||||
end
|
||||
end
|
||||
|
||||
defp status_in(:slow_blink), do: IO.ANSI.blink_slow()
|
||||
|
|
|
@ -23,7 +23,9 @@ defmodule FarmbotCore.LogExecutor do
|
|||
do: level,
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"coverage_options": {
|
||||
"coverage_options": {
|
||||
"treat_no_relevant_lines_as_covered": true,
|
||||
"minimum_coverage": 35
|
||||
"minimum_coverage": 39
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ defmodule FarmbotExt.AMQP.AutoSyncChannel do
|
|||
Tool
|
||||
)
|
||||
|
||||
# Sync messgaes about these assets
|
||||
# Sync messgages about these assets
|
||||
# should not be cached. They need to be applied
|
||||
# in real time.
|
||||
@no_cache_kinds ~w(
|
||||
|
@ -136,11 +136,8 @@ defmodule FarmbotExt.AMQP.AutoSyncChannel do
|
|||
id = data["id"] || String.to_integer(id_str)
|
||||
_ = 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
|
||||
|
||||
:ok = ConnectionWorker.rpc_reply(chan, device, label)
|
||||
|
|
|
@ -66,7 +66,6 @@ defmodule FarmbotExt.API.EagerLoader do
|
|||
* a remote `id` field.
|
||||
"""
|
||||
def cache(%Changeset{data: %module{}} = changeset) do
|
||||
Logger.info("Caching #{inspect(changeset)}")
|
||||
id = Changeset.get_field(changeset, :id)
|
||||
updated_at = Changeset.get_field(changeset, :updated_at)
|
||||
id || change_error(changeset, "Can't cache a changeset with no :id attribute")
|
||||
|
|
|
@ -51,8 +51,6 @@ defmodule FarmbotExt.Bootstrap do
|
|||
end
|
||||
|
||||
def try_auth(email, server, password, _secret) do
|
||||
Logger.debug("using password to auth")
|
||||
|
||||
with {:ok, tkn} <- Authorization.authorize_with_password(email, password, server),
|
||||
_ <- update_config_value(:string, "authorization", "token", tkn),
|
||||
{:ok, pid} <- Supervisor.start_child(FarmbotExt, Bootstrap.Supervisor) do
|
||||
|
|
|
@ -105,7 +105,7 @@ defmodule AutoSyncChannelTest do
|
|||
})
|
||||
|
||||
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
|
||||
|
||||
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"}})
|
||||
assert_receive {:rpc_reply_called, %{fake: :chan}, "device_15", "xyz"}
|
||||
assert_receive {:rpc_reply_called, %{fake: :chan}, "device_15", "xyz"}, 1000
|
||||
end
|
||||
|
||||
test "ignores asset deletion when auto_sync is off" do
|
||||
|
@ -136,9 +136,10 @@ defmodule AutoSyncChannelTest do
|
|||
end)
|
||||
|
||||
send(pid, {:basic_deliver, payload, %{routing_key: key}})
|
||||
assert_receive :called_auto_sync?
|
||||
assert_receive :called_auto_sync?, 1200
|
||||
end
|
||||
|
||||
@tag :blinky
|
||||
test "handles Device assets" do
|
||||
%{pid: pid} = under_normal_conditions()
|
||||
test_pid = self()
|
||||
|
@ -152,7 +153,7 @@ defmodule AutoSyncChannelTest do
|
|||
end)
|
||||
|
||||
send(pid, {:basic_deliver, payload, %{routing_key: key}})
|
||||
assert_receive {:update_called, "Device", 999, %{}}
|
||||
assert_receive {:update_called, "Device", 999, %{}}, 1200
|
||||
end
|
||||
|
||||
def simple_asset_test_singleton(module_name) do
|
||||
|
@ -175,9 +176,10 @@ defmodule AutoSyncChannelTest do
|
|||
|
||||
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
|
||||
|
||||
@tag :blinky
|
||||
test "handles auto_sync of 'no_cache' when auto_sync is false" do
|
||||
test_pid = self()
|
||||
%{pid: pid} = under_normal_conditions()
|
||||
|
@ -196,8 +198,8 @@ defmodule AutoSyncChannelTest do
|
|||
end)
|
||||
|
||||
send(pid, {:basic_deliver, payload, %{routing_key: key}})
|
||||
assert_receive :called_auto_sync?
|
||||
assert_receive {:update_called, "FbosConfig", 999, %{"foo" => "bar"}}
|
||||
assert_receive :called_auto_sync?, 1200
|
||||
assert_receive {:update_called, "FbosConfig", 999, %{"foo" => "bar"}}, 1200
|
||||
end
|
||||
|
||||
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}})
|
||||
|
||||
assert_receive {:update_called, ^module_name, 999, %{"foo" => "bar"}}
|
||||
assert_receive {:update_called, ^module_name, 999, %{"foo" => "bar"}}, 3000
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,9 +8,16 @@ defmodule FarmbotExt.AMQP.BotStateChannelTest do
|
|||
setup :verify_on_exit!
|
||||
setup :set_mimic_global
|
||||
|
||||
test "read_status" do
|
||||
# {:ok, pid} = GenServer.start_link(BotStateChannel, [jwt: %{}])
|
||||
# expect(BotState, :fetch, 1, fn -> %{} end)
|
||||
# BotStateChannel.read_status(pid)
|
||||
defmodule FakeState do
|
||||
defstruct conn: %{fake: :conn}, chan: "fake_chan_", jwt: "fake_jwt_", cache: %{fake: :cache}
|
||||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -6,7 +6,8 @@ Mimic.copy(FarmbotCore.Asset.Command)
|
|||
Mimic.copy(FarmbotCore.Asset.Query)
|
||||
Mimic.copy(FarmbotExt.AMQP.ConnectionWorker)
|
||||
Mimic.copy(FarmbotExt.API)
|
||||
|
||||
Mimic.copy(AMQP.Channel)
|
||||
Mimic.copy(FarmbotCore.LogExecutor)
|
||||
if timeout do
|
||||
ExUnit.start(assert_receive_timeout: String.to_integer(timeout))
|
||||
else
|
||||
|
|
|
@ -300,20 +300,10 @@ defmodule FarmbotFirmware do
|
|||
name: state.reset
|
||||
) do
|
||||
{:ok, pid} ->
|
||||
Logger.debug(
|
||||
"Firmware reset #{state.reset} started. #{
|
||||
inspect(state.transport_args)
|
||||
}"
|
||||
)
|
||||
|
||||
{:noreply, %{state | reset_pid: pid}}
|
||||
|
||||
# TODO(Rick): I have no idea what's going on here.
|
||||
{:error, {:already_started, pid}} ->
|
||||
Logger.debug(
|
||||
"Firmware reset complete. #{inspect(state.transport_args)}"
|
||||
)
|
||||
|
||||
{:noreply, %{state | reset_pid: pid}}
|
||||
|
||||
error ->
|
||||
|
|
Loading…
Reference in New Issue