I need to see all channel events and params received by application and their outputs.
For now I use this construction:
defmodule AppWeb.SomeChannel do
...
# wraps all handle_in
def handle_in(event, params, socket) do
Logger.debug("#{event} - #{inspect params}")
my_handle_in(event, params, socket)
end
my_handle_in("some_event", params, socket) do
...
end
my_handle_in("some_event2", params, socket) do
...
end
# And others
...
end
And every channel has this wrapper. I understand how to dry it with macro.
But Is there a some better approach like we can do with plug?
Plugs don’t work with channels, so it’s not possible.
If it’s for debugging I would suggest you look into tracing. With tracing you can “listen” to all calls to a function without changing the code in any way. I would recommend the recon package. Using it calling (from iex):