navinpeiris / logster

Easily parsable single line, plain text and JSON logger for Plug and Phoenix applications
MIT License
205 stars 28 forks source link

How to remove Phoenix default logging #21

Open tmaszk opened 4 years ago

tmaszk commented 4 years ago

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.

Nax commented 4 years ago

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

config :phoenix, :logger, false
zillou commented 3 years ago

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