How to configure Phoenix.LiveView.Socket logging levels

I have a deployed Phoenix LiveView App.
When I start it with a shell, I see output like this:

10:43:25.306 request_id=F_xtup9AcaphOX8AAEvB [info] GET /some-page/
10:43:25.312 request_id=F_xtup9AcaphOX8AAEvB [info] Sent 200 in 6ms
10:46:14.756 [info] CONNECTED TO Phoenix.LiveView.Socket in 42µs
Transport: :websocket
Serializer: Phoenix.Socket.V2.JSONSerializer
Parameters: %{“_csrf_token” => “…”, “_live_referer” => “undefined”, “_mounts” => “0”, “_track_static” => %{“0” => “https://webpage.com/assets/app-777.css?vsn=d”, “1” => “https://webpage.com/assets/6665.js?vsn=d”}, “vsn” => “2.0.0”}

How to configure (turn off) this messages?
Is there a drawback when I turn these off? Do I miss some important stuff?
Can the debug levels be tweaked in the shell at runtime?

1 Like

I am not at my computer but read this: Phoenix.Logger — Phoenix v1.7.14

Search that page for the word “level”

I changed endpoint.ex like this:
socket “/live”, Phoenix.LiveView.Socket,
websocket: [connect_info: [session: @session_options], log: false],
longpoll: [connect_info: [session: @session_options], log: false]

The CONNECTED TO Phoenix.LiveView.Socket message is gone.

However the request_id lines are still present. How to find out where they are coming from and how to disable them?

I strongly suggest using log: :warning instead of log: false.

You will want to see warning/error/alert/critical/emergency level logs. Hopefully they never happen but you will definitely want to see when they do.

I am not sure where the other logs come from. If I get some free time this week, I will dig into it.

Update: I was wrong about log: :warning. This actually changes the level of the logs printed! That is, logs which are normally :info are now :warning.

To get rid of the logs with the request_id metadata in them, do something like this

  plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint], log: false

That lives in endpoint.ex. You should already have this plug in there.

You can have more control over which routes get logged by using an MFA (module-function-arity) tuple.

plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint], log: {__MODULE__, :log_level, []}

@quiet_paths ["health", "healthz", "healthcheck", "favicon.ico"]
def log_level(%{path_info: [head | _]}) when head in @quiet_paths, do: false
def log_level(_), do: :info 

This would do the usual logging except for paths /health, /healthz, etc.

Thanks. That looks nice.
What is a good way to make the log_level runtime configurable?
I’d like to switch e.g. from :info to false. Therefore I need some state for the log_level function.

Exactly - I experimented with the :info, :warning settings.
I changed it to :debug. That way they should not be longer printed in the deployed version.

Here is some info about logging in elixir: