macro Util.lgi(): log names (expressions) and values

This commit is contained in:
Helmut Merz 2026-06-07 07:17:21 +02:00
parent 5123c1b3e8
commit 88d6544749
4 changed files with 11 additions and 2 deletions

View file

@ -58,7 +58,7 @@ defmodule Scopes.CSys do
# send shortcuts
def send_message(rcvr, head, data \\ %{}) do
Logger.info rcvr: inspect(rcvr), head: inspect(head), data: inspect(data)
Logger.debug rcvr: inspect(rcvr), head: inspect(head), data: inspect(data)
Actor.send(rcvr, Shape.create(head, data: data))
end

View file

@ -74,7 +74,7 @@ defmodule Scopes.CSys.Program do
limit = args[:limit]
data = Shape.data(msg)
state = CSys.state(scope)
Logger.info data: data, state_value: state.value, threshold: threshold, self: self()
Logger.debug data: data, state_value: state.value, threshold: threshold, self: self()
value_n = state.value + data.value
if value_n >= threshold do
value_out = limit && rem(value_n - 1, limit) + limit || value_n

View file

@ -6,4 +6,12 @@ defmodule Scopes.Util do
Enum.zip(names, fields) |> Map.new
end
end
defmacro lgi(fields) do
#IO.inspect(fields)
quote do
require Logger
Logger.info(Scopes.Util.fields_info(unquote(fields)))
end
end
end

View file

@ -8,6 +8,7 @@ defmodule Scopes.UtilTest do
test "fields" do
{a, b, c} = {17, 22, 42}
assert %{"a" => 17, "b" => 22, "c" => 42} = Util.fields_info([a, b, c])
Util.lgi([a, b, c])
end
end
end