Add local network logger if setup
parent
c8cbe5f5d8
commit
6919c87abd
|
@ -0,0 +1,36 @@
|
|||
defmodule Farmbot.Logger.NetLogger do
|
||||
@moduledoc false
|
||||
use GenStage
|
||||
use Farmbot.Logger
|
||||
|
||||
def start_link do
|
||||
GenStage.start_link(__MODULE__, [], name: __MODULE__)
|
||||
end
|
||||
|
||||
def init([]) do
|
||||
send self(), :try_connect
|
||||
{:consumer, %{client: nil}, subscribe_to: [Farmbot.Logger]}
|
||||
end
|
||||
|
||||
def handle_events(_e, _from, %{client: nil} = state) do
|
||||
{:noreply, [], state}
|
||||
end
|
||||
|
||||
def handle_events(events, _from, %{client: client} = state) do
|
||||
for e <- events do
|
||||
log = %NetLogger.Log{message: e.message, time: e.time, level: e.level, verbosity: e.verbosity}
|
||||
NetLogger.UDP.Client.log(client, log)
|
||||
end
|
||||
{:noreply, [], state}
|
||||
end
|
||||
|
||||
def handle_info(:try_connect, %{client: nil} = state) do
|
||||
case NetLogger.UDP.Client.start_link([]) do
|
||||
{:ok, client} ->
|
||||
{:noreply, [], %{state | client: client}}
|
||||
{:error, _} ->
|
||||
Process.send_after(self(), :try_connect, 30_000)
|
||||
{:noreply, [], state}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -27,6 +27,7 @@ defmodule Farmbot.System.Supervisor do
|
|||
after_init_children = [
|
||||
supervisor(Farmbot.System.Updates, []),
|
||||
worker(Farmbot.EasterEggs, []),
|
||||
worker(Farmbot.Logger.NetLogger, [])
|
||||
]
|
||||
|
||||
all_children = before_init_children ++ init_mods ++ after_init_children
|
||||
|
|
3
mix.exs
3
mix.exs
|
@ -122,7 +122,8 @@ defmodule Farmbot.Mixfile do
|
|||
{:recon, "~> 2.3.2"},
|
||||
{:ring_logger, "~> 0.4.1"},
|
||||
{:bbmustache, "~> 1.5"},
|
||||
{:apex, "~>1.2"}
|
||||
{:apex, "~> 1.2"},
|
||||
{:net_logger, "~> 0.1"}
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
"nerves": {:hex, :nerves, "1.1.0", "acc8af6d508793aa68be3aeefda7be4e01c2bc4cfcb729e335d60212d2cfcf12", [:mix], [{:distillery, "~> 1.4", [hex: :distillery, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"nerves_leds": {:hex, :nerves_leds, "0.8.0", "193692767dca1a201b09113d242648493b9be0087bab83ebee99c3b0a254f5e1", [:mix], [], "hexpm"},
|
||||
"nerves_uart": {:hex, :nerves_uart, "1.2.0", "195424116b925cd3bf9d666be036c2a80655e6ca0f8d447e277667a60005c50e", [:mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"net_logger": {:hex, :net_logger, "0.1.0", "59be302c09cf70dab164810c923ccb9a976eda7270e5a32b93ba8aeb850de1d6", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:uuid, "~> 1.1", [hex: :uuid, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"},
|
||||
"phoenix_html": {:hex, :phoenix_html, "2.11.2", "86ebd768258ba60a27f5578bec83095bdb93485d646fc4111db8844c316602d6", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"plug": {:hex, :plug, "1.6.1", "c62fe7623d035020cf989820b38490460e6903ab7eee29e234b7586e9b6c91d6", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
|
|
Loading…
Reference in New Issue