Phoenix Socket prevents Plug.Logger from printing logs. Why

Hi,

I am running a phoenix server app. I am using observer as well to analyse performance.

When looking at the wobserver on a browser, I see the usual Plug.Logger output being printed out. E.g

2020-09-02T11:45:53.932: [info] module=Plug.Logger function=call/2 :  GET /wobserver/api/system
2020-09-02T11:45:53.933: [info] module=Plug.Logger function=call/2 :  Sent 200 in 425µs

What I noticed though is when I add the following line to my endpoint.ex file, the Plug.Logger doesn’t seem to be called, and the logs are not coming through.

socket("/wobserver", Wobserver.Web.PhoenixSocket)

I am just curious as to why this is, as the “plug Plug.Logger” line is still present in the endpoint code. Any input would be greatly appreciated.

Here is the Endpoint file:

defmodule MyApp.Endpoint do
  use Phoenix.Endpoint, otp_app: :app_alpha

  socket("/socket", MyOtherSocket)


  ###########################################################
  # With this line added, the logging stops
  socket("/wobserver", Wobserver.Web.PhoenixSocket)
  ###########################################################

  # Serve at "/" the static files from "priv/static" directory.
  #
  # You should set gzip to true if you are running phoenix.digest
  # when deploying your static files in production.
  plug(Plug.Static, at: "/", from: :my_app, gzip: false)

  # Code reloading can be explicitly enabled under the
  # :code_reloader configuration of your endpoint.
  if code_reloading? do
    socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
    plug(Phoenix.LiveReloader)
    plug(Phoenix.CodeReloader)
  end

  plug(Plug.RequestId)
  plug(Plug.Logger)

  plug(
    Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],
    pass: ["*/*"],
    json_decoder: Poison,
    length: 115_343_360 ## Max upload size of 110 MB
  )

  plug(Plug.MethodOverride)
  plug(Plug.Head)

  # The session will be stored in the cookie and signed,
  # this means its contents can be read but not tampered with.
  # Set :encryption_salt if you would also like to encrypt it.
  plug(
    Plug.Session,
    store: :cookie,
    key: "_slc_key",
    signing_salt: "mqaIqryo"
  )

  plug(MyApp.Router)

  def init(_key, config) do
    AppManager.update_endpoint_config(config)
  end
end

Socket requests do not go through the plug pipeline, they do not work on conns so they are handled separately :slight_smile: . Check the socket docs to see your customization options around them.

3 Likes