Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print response body to stdout/stderr on Rails

I would like to print out response body generated by my app to stdout/stderr for debugging purposes. The traffic is server-server so I cannot use client tools to get hold of http traffic.

There is a mention of puts @response.body in http://api.rubyonrails.org/classes/ActionDispatch/Response.html, however in my app controller @response is undefined. Is there a way for me to print response body to logs in my rails app, and if so, how?


Based on the answer given, did it like this:

after_filter :print_response_body, :only => [:index]

def print_response_body 
  $stderr.puts response.body
end
like image 208
eis Avatar asked Mar 12 '13 18:03

eis


1 Answers

In your controller, try

after_filter do
  puts response.body
end
like image 140
Seamus Abshere Avatar answered Oct 03 '22 16:10

Seamus Abshere