How to log the raw http response built by Phoenix right before it is sent to the client?

logging
phoenix
http

#1

I would like to know how can we display the http response (header and body) built by Phoenix right before it is sent to the client.


#2

You can’t, as the first byte might have already been sent before the last one is calculated, as conn is basically a sink you stream into.


#3

Really ? well, right after would work as well. Basically I would like a log of what has been sent to the client.


#4

:plug doesn’t support that as well as far as I know.


#5

What about “outside” phoenix? Google for “nginx lua log response body” if this is of any help… If you’re on production you may want to use a filter and not log every request… :wink:


#6

The Plug.Conn.register_before_send/2 seems to be what you want @abtrapp


#7

Wasn’t my question, but I didn’t knew that one, so I suggested a possible solution until a better one appeared. register_before_send looks good. So tnx, I’m sure that I will need this one day! :slight_smile: