archimondain
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.
Marked As Solved
marciol
The Plug.Conn.register_before_send/2 seems to be what you want @abtrapp
Also Liked
hubertlepicki
Remember the register_before_send may not be called in case of errors on application side, for example.
User will get some response, but your handler may not be called.
If you need to handle logging all responses, you may want to put something like a reverse proxy in front of your app, and configure it to do full logging there.
NobbZ
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.
abtrapp
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… ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









