Remove Farmbot Logger colors

* Fixes espeak trying to speak ansi colors
* allows espeak to be specified as the sole channel
pull/974/head
Connor Rigby 2019-07-09 10:21:38 -07:00
parent c09ed30677
commit fa96e2c8fd
No known key found for this signature in database
GPG Key ID: 29A88B24B70456E0
3 changed files with 10 additions and 21 deletions

View File

@ -84,20 +84,7 @@ defmodule FarmbotCore.Log do
defimpl String.Chars, for: Log do
def to_string(log) do
if log.meta[:color] && function_exported?(IO.ANSI, log.meta[:color], 0) do
"#{apply(IO.ANSI, log.meta[:color], [])}#{log.message}#{color(:normal)}\n"
else
"#{color(log.level)}#{log.message}#{color(:normal)}\n"
end
IO.iodata_to_binary(log.message)
end
defp color(:debug), do: IO.ANSI.light_blue()
defp color(:info), do: IO.ANSI.cyan()
defp color(:busy), do: IO.ANSI.blue()
defp color(:success), do: IO.ANSI.green()
defp color(:warn), do: IO.ANSI.yellow()
defp color(:error), do: IO.ANSI.red()
defp color(:normal), do: IO.ANSI.normal()
defp color(_), do: IO.ANSI.normal()
end
end

View File

@ -110,14 +110,15 @@ defmodule FarmbotCore.Logger do
end
defp elixir_log(%Log{} = log) do
# TODO Connor - fix time
logger_meta = [
application: :farmbot,
function: log.function,
file: log.file,
line: log.line,
module: log.module,
channels: log.meta[:channels] || log.meta["channels"]
channels: log.meta[:channels] || log.meta["channels"],
verbosity: log.verbosity
# TODO Connor - fix time
# time: time
]

View File

@ -26,11 +26,12 @@ defmodule LoggerBackendEspeak do
def handle_event({_level, _pid, {Logger, msg, _timestamp, meta}}, %{port: espeak} = state) do
should_espeak? =
Enum.find(meta[:channels] || [], fn
:espeak -> true
"espeak" -> true
_ -> false
end)
meta[:channels] == :espeak ||
Enum.find(meta[:channels] || [], fn
:espeak -> true
"espeak" -> true
_ -> false
end)
if should_espeak? do
_ = Port.command(espeak, IO.iodata_to_binary(msg) <> "\n")