logster icon indicating copy to clipboard operation
logster copied to clipboard

How to remove Phoenix default logging

Open tmaszk opened this issue 5 years ago • 2 comments

The logster README shows how to log new messages with logster, but it doesn't show how to remove the Phoenix generated log statements. To me, the README implies that you can remove logging by removing a plug Plug.Logger line, but that line doesn't exist in a new Phoenix generated app.

I found this Phoenix issue that details how to remove the Phoenix generated log statements, https://github.com/phoenixframework/phoenix/issues/3483#issuecomment-549484373

I used this technique in my project to keep Phoenix from generating redundant messages with logster. Added the following lines to m Application.ex file in my Phoenix project.

    # Disable Phoenix logging, using Logster instead
    :ok = :telemetry.detach({Phoenix.Logger, [:phoenix, :endpoint, :start]})
    :ok = :telemetry.detach({Phoenix.Logger, [:phoenix, :endpoint, :stop]})

Not sure if you want to update the README or not, but I thought I'd mention it in case it saves someone else some time.

tmaszk avatar Dec 24 '19 13:12 tmaszk

The most recent Phoenix docs suggests the following to disable the built-in logger:

config :phoenix, :logger, false

Nax avatar Aug 23 '20 21:08 Nax

According to Phoenix.Logger's doc

Disable logging: In your endpoint plug Plug.Telemetry, ..., log: Logger.level | false

The setup for replacing Phoenix.Logger with Logster should be like below:

-  plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
+  plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint], log: false
+  plug Logster.Plugs.Logger

zillou avatar Apr 29 '21 10:04 zillou