How to Log something in Controller when Phoenix Server is running?

前端 未结 2 1594
陌清茗
陌清茗 2021-02-01 00:35

I\'m trying to print some debug information from one of my Controllers in my Phoenix app when the server is running.

defmo         


        
2条回答
  •  故里飘歌
    2021-02-01 00:58

    Okay, turns out it's pretty straight forward. You need to require the Logger elixir module in your controller and call one of it's methods to log your text.

    defmodule PhoenixApp.TopicController do
        require Logger
    
        def index(conn, params) do
            Logger.info  "Logging this text!"
            Logger.debug "Var value: #{inspect(params)}"
    
            # ...
        end
    end
    

    Supported levels are:

    • :debug - for debug-related messages
    • :info - for information of any kind
    • :warn - for warnings
    • :error - for errors

    Source: Elixir - Logger Documentation

提交回复
热议问题