Limiting IO.inspect/2 output

almirsarajcic

almirsarajcic

Created 6 months ago

Are you using the function IO.inspect/2 for debugging? Are you getting overwhelmed with the outputs of large structs?

Try passing the :limit option. It limits the number of items shown for any collection.

{:ok,
  socket
  # some assigns
  # ...
  |> IO.inspect(label: "socket", limit: 5)}

# prints
socket: #Phoenix.LiveView.Socket<
  id: "phx-GA-FuxsBgRdd1gOm",
  endpoint: ElixirDropsWeb.Endpoint,
  view: ElixirDropsWeb.DropLive.Index,
  parent_pid: nil,
  root_pid: nil,
  ...
>

# instead of a huge Phoenix.LiveView.Socket struct

Check other IO.inspect/2 options: https://hexdocs.pm/elixir/Inspect.Opts.html.