132 words, 1 min read

When debugging in Elixir, I often use IO.inspect/2 to print the contents of a variable:

whatever
|> IO.inspect()

To improve readability, I usually add a label and format the output nicely:

whatever
|> IO.inspect(label: "Feeds", pretty: true)

However, this still prints plain text, without any syntax highlighting.

To enable colors in the terminal, you can pass the :syntax_colors option with IO.ANSI.syntax_colors/0:

whatever
|> IO.inspect(label: "Feeds", pretty: true, syntax_colors: IO.ANSI.syntax_colors())

This renders the output with ANSI color codes, making structured data much easier to read—especially maps and structs.

If you're using this often, consider creating a helper function:

defmodule Debug do
def print(term, label \\ "Debug") do
IO.inspect(term, label: label, pretty: true, syntax_colors: IO.ANSI.syntax_colors())
end
end

Then use it like this:

Debug.print(whatever, "Feeds")

Now your debug output is both informative and visually pleasant.