Failing to remove info level logs from plug and phoenix

:wave:

I’ve added

config :logger,
  compile_time_purge_matching: [
    [application: :phoenix, level_lower_than: :warn],
    [application: :plug, level_lower_than: :warn]
  ]

to my config (dev.exs) and recompiled phoenix and plug with mix deps.compile plug phoenix --force (using dev env) but the info level logs still show up (in dev env).

The global logger log level is set to :debug.

What have I done wrong?

elixir -v

Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.9.0 (compiled with Erlang/OTP 22)

Not specifying level_lower_than seems to work as

config :logger,
  compile_time_purge_matching: [
    [application: :phoenix],
    [application: :plug]
  ]

removes all logs as seen from the compilation warnings

==> plug
Compiling 1 file (.erl)
Compiling 39 files (.ex)
warning: variable "log" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/plug/session/cookie.ex:131: Plug.Session.COOKIE.decode/3

warning: variable "log" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/plug/session/cookie.ex:158: Plug.Session.COOKIE.decode/3

warning: variable "level" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/plug/logger.ex:26: Plug.Logger.call/2

warning: System.stacktrace/0 outside of rescue/catch clauses is deprecated. If you want to support only Elixir v1.7+, you must access __STACKTRACE__ inside a rescue/catch. If you want to support earlier Elixir versions, move System.stacktrace/0 inside a rescue/catch
  lib/plug/conn/wrapper_error.ex:23

Generated plug app
==> phoenix
Compiling 67 files (.ex)
warning: variable "level" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/phoenix/logger.ex:107: Phoenix.Logger.phoenix_endpoint_start/4

warning: variable "level" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/phoenix/logger.ex:116: Phoenix.Logger.phoenix_endpoint_stop/4

warning: variable "level" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/phoenix/logger.ex:132: Phoenix.Logger.phoenix_error_rendered/4

warning: variable "level" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/phoenix/logger.ex:154: Phoenix.Logger.phoenix_router_dispatch_start/4

warning: variable "level" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/phoenix/logger.ex:182: Phoenix.Logger.phoenix_socket_connected/4

warning: variable "level" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/phoenix/logger.ex:257: Phoenix.Logger.channel_log/3

Generated phoenix app

Seems like since level is settable for phoenix logger at runtime it’s not purgeable with this option.

My goal was to remove GET / ... Sent in ... logs in :info level and it was possible by setting :log option to :debug for Plug.Logger.

plug Plug.Logger, log: :debug

# and in config
config :logger, level: :info
5 Likes

Actually that didn’t work, the logs still appear but now for phoenix sockets and controllers.

[info] CONNECTED TO Phoenix.LiveView.Socket in 195µs
  Transport: :websocket
  Serializer: Phoenix.Socket.V2.JSONSerializer
  Connect Info: %{}
  Parameters: %{"vsn" => "2.0.0"}

Line: 183
Function: "phoenix_socket_connected/4"
Module: Phoenix.Logger
Application: :phoenix
File: "lib/phoenix/logger.ex"
[info] Converted error Phoenix.Router.NoRouteError to 404 response

Line: 133
Function: "phoenix_error_rendered/4"
Module: Phoenix.Logger
Application: :phoenix
File: "lib/phoenix/logger.ex"

even though I have

use Phoenix.Controller, log: false

set in app_web.ex and

  socket "/live", Phoenix.LiveView.Socket, log: false

  socket "/socket", App.Web.UserSocket,
    websocket: true,
    longpoll: false,
    log: false

set in endpoint.ex.

Phoenix version 1.4.9


Seems like the log level option for "phoenix_error_rendered/4" comes from a module attribute, so my changes to config are unlike to change anything … Do I need to recompile the :phoenix dependency? Seems like I need to set log: false in for endpoint’s render_errors option. I wonder if I’m missing some obvious way to turn off all logs in phoenix. Or rather make them at :debug level.


Very strange, the function that logs "phoenix_error_rendered/4" doesn’t receive the log level (according to the gist below), but that would mean that it should use :debug level but uses :info instead as I see it logged.


Trace for socket connect log:

# Phoenix.Logger.phoenix_socket_connected(
[:phoenix, :socket_connected],
%{duration: 189593},
%{connect_info: %{}, endpoint: Web.Endpoint, log: :info, params: %{"vsn" => "2.0.0"}, result: :ok, serializer: Phoenix.Socket.V2.JSONSerializer, transport: :websocket, user_socket: Phoenix.LiveView.Socket, vsn: "2.0.0"}, 
:ok)

Log level is :info, even though it’s set to false in the endpoint …


Tried recompiling from scratch, still socket_connected gets logged. Giving up for today :slight_smile: Would need to find an easier way to do the logging, since in phoenix logs are neither purgeable at compile-time, nor settable at runtime … unless I’m holding it wrong.