defmodule AugieWeb.LoggerLive do use Phoenix.LiveView alias Augie.Sensor import Calendar.Strftime require Logger @moduledoc """ A Liveview which displays logs from the co-processor. """ def render(assigns) do ~L"""

Logs

<%= if Enum.any?(@logs) do %> <%= for log <- @logs do %> <% end %>
<%= strftime!(log.at, "%Y-%m-%d %H:%M:%S") %> <%= log.message %>
<% else %> No logs to show. <% end %>
""" end def mount(_params, _context, socket) do if connected?(socket), do: CommunityTheatre.subscribe(Logger) {:ok, assign(socket, logs: [])} end def handle_info( {CommunityTheatre, %{topic: Sensor.Logger, payload: sample}}, %{assigns: logs} = socket ) do Logger.info("Received log: #{inspect(sample)}") {:noreply, assign(socket, logs: [sample | logs])} end end