Elixir:
Printing debug output

How to:

defmodule DebugExample do
  def show_debug_output do
    name = "Elixir"

    IO.inspect(name, label: "Debug")
    # further processing
  end
end

DebugExample.show_debug_output()
# Output:
# Debug: "Elixir"

This shows the simplest way to print something to the console using IO.inspect/2. The label option adds a custom prefix, making the output easier to spot.

Deep Dive

Elixir’s IO.inspect/2 function is akin to puts in Ruby or console.log in JavaScript. It’s great for quick-and-dirty debugging, a practice as old as programming itself.

Alternatives in Elixir include using the Logger module for more systematic application-level logging. This is more configurable and suitable for production.

For implementation details, IO.inspect/2 returns the given data, making it easy to insert into a pipeline without affecting functionality. Historically, Elixir has always emphasized developer tooling, and functions like IO.inspect/2 embody this by making debugging a more integrated experience.

See Also