How do you debug a Sinatra app like a Rails app?

nova picture nova · Sep 1, 2009 · Viewed 34.8k times · Source

In my main Sinatra controller, I want to debug the params hash after it is POSTed from a form.

I have added:

puts params.inspect

and

set :logging, :true

The params.inspect works if everything goes well. But if an error happens before the controller is executed I'm not getting any information about the error like I would in Rails by default.

What's the best way to get useful debug info?

This example did not work at all (the app wouldn't even start after I added this code):

configure do 
  Log = Logger.new("sinatra.log")
  Log.level  = Logger::INFO 
end

followed by:

Log.info "#{@users.inspect}"

Answer

BaroqueBobcat picture BaroqueBobcat · Sep 1, 2009

You could try adding a before filter that prints out the parameters

before do
  puts '[Params]'
  p params
end