logster
logster copied to clipboard
How to remove Phoenix default logging
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.
The most recent Phoenix docs suggests the following to disable the built-in logger:
config :phoenix, :logger, false
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