Elixir Language Debugging Tips Debugging with IO.inspect/1


Example

It is possible to use IO.inspect/1 as a tool to debug an elixir program.

defmodule MyModule do
  def myfunction(argument_1, argument_2) do
    IO.inspect(argument_1)
    IO.inspect(argument_2)
  end
end

It will print out argument_1 and argument_2 to the console. Since IO.inspect/1 returns its argument it is very easy to include it in function calls or pipelines without breaking the flow:

do_something(a, b)
|> do_something_else(c)

# can be adorned with IO.inspect, with no change in functionality:

do_something(IO.inspect(a), IO.inspect(b))
|> IO.inspect
do_something(IO.inspect(c))