Runtime “warn once” strategy

In case anyone stumbles across this question in their own question, the following is suitable for me needs:

  defmacro warn_once(key, message, level \\ :warn) do
    caller = __CALLER__.module

    quote do
      require Logger

      if :persistent_term.get({unquote(caller), unquote(key)}, true) do
        Logger.unquote(level)(unquote(message))
        :persistent_term.put({unquote(caller), unquote(key)}, nil)
      end
    end
  end

I wrap this at the calling site with a macro to make the inclusion of this generated code dependent on configuration, and whether :persistent_term exists.