How to change log level of plugs in Phoenix Endpoint

Hi there,

We have a Phoenix Endpoint with a pretty standard configuration. In particular we have Plug.Parsers setup to try to parse JSON requests:

plug Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],

When we get a request with a body and a JSON content type header, this plug tries to decode the body as JSON, if it fails it logs an error like this:

[debug] ** (Plug.Parsers.ParseError) malformed request, a Jason.DecodeError exception was raised with message "unexpected byte at position 2: 0x7B ('{')"
    (plug 1.11.1) lib/plug/parsers/json.ex:90: Plug.Parsers.JSON.decode/2
    (plug 1.11.1) lib/plug/parsers.ex:339: Plug.Parsers.reduce/8

It logs it at the debug log level though, in production we don’t see this message because we don’t print debug-level messages in production.

Is there any way I can have these errors printed at a different log level? I think maybe this: phoenix/pipeline.ex at 8d2b33ac9691bd624ede602088d213f89600d233 · phoenixframework/phoenix · GitHub is where the log level for these messages is set. If that’s the case I can’t see a practical way to change it but maybe I’m missing something?


Could it be that you have UTF-8 BOM bytes on positions 0 and 1?

Thanks @dimitarvp that may be true. What I was trying to ask though was how to change the log level of the error message.