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



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.


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.


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


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


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:


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


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: