Hi,
Would there be a way to add a :label option to dbg/2 similar to IO.inspect/2?
Thanks …
You can configure dbg
to use a different function under the hood. Check the docs, there’s an example specifically using IO.inspect
- Kernel — Elixir v1.16.0-dev .
2 Likes
Thanks, I wasn’t aware of that!
I just coded my own dbg
callback (and I can still fall back to the native Elixir dbg
by using dbg(debug: true)
defmodule PhoenixStorybook.Dbg do
@moduledoc false
def debug_fun(code, options, caller, device) do
case Keyword.pop(options, :debug, false) do
{true, options} -> Macro.dbg(code, options, caller)
{_, options} -> custom_debug(code, options, caller, device)
end
end
defp custom_debug(code, _options, caller, device) do
alias PhoenixStorybook.Dbg
quote do
result = unquote(code)
IO.puts(
unquote(device),
Dbg.light_green(
"\n#{unquote(Path.relative_to(caller.file, File.cwd!()))}:#{unquote(caller.line)}"
This file has been truncated. show original
1 Like