rogergl
rogergl

Reputation: 3781

How to pretty print conn content?

I tried the following

def index(conn, _params) do
    Logger.debug conn
     ......

But I get

protocol String.Chars not implemented for %Plug.Conn

I even tried Apex but that didn't worked either.

Upvotes: 21

Views: 10232

Answers (4)

Patrick Oscity
Patrick Oscity

Reputation: 54714

You should be able to use Kernel.inspect/2 to pretty print conn:

Logger.debug inspect(conn)

Upvotes: 9

Rob Raisch
Rob Raisch

Reputation: 17367

You can indeed use Kernel.inspect/2 to pretty-print the contents of the %Plug.Conn{} using:

def index(conn, _params) do
  :logger.info inspect(conn, pretty: true)
  ....
end

Note that previous answers using Logger should mention that you need to require Logger before you use it, as in:

require Logger

def index(conn, _params) do
  Logger.info inspect(conn, pretty: true)
  ....
end

Upvotes: 6

zhulinpinyu
zhulinpinyu

Reputation: 629

IO.inspect is well. I used in my side project, like ruby awsome_print

Upvotes: 0

Brian Marick
Brian Marick

Reputation: 1440

Use inspect conn, pretty: true

... or:

inspect conn, pretty: true, limit: 30000

... since Conn structures are pretty big.

Upvotes: 39

Related Questions