How to pretty print conn content?

前端 未结 4 1456
天涯浪人
天涯浪人 2021-02-12 20:43

I tried the following

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

But I get

protocol String.Chars not impleme         


        
相关标签:
4条回答
  • 2021-02-12 21:19

    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
    
    0 讨论(0)
  • 2021-02-12 21:26

    Use inspect conn, pretty: true

    ... or:

    inspect conn, pretty: true, limit: 30000

    ... since Conn structures are pretty big.

    0 讨论(0)
  • 2021-02-12 21:30

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

    Logger.debug inspect(conn)
    
    0 讨论(0)
  • 2021-02-12 21:39

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

    0 讨论(0)
提交回复
热议问题