SQL Logging: Gemified and Now for Rails 3

Posted by on Nov 22, 2010 in Blog, News | Tags: , | No Comments

Of the handful of plug-ins I’ve written for Rails over the years, the one I install on new projects almost with thinking is sql_logging. I wrote that plug-in almost three years ago and it continues to work on Rails 2.3 apps today.

That isn’t true on Rails 3, though, so over the last few days I’ve taken the time to reevaluate the plug-in and figure out how to do the same work in Rails 3. The result is the new sql-logging gem. The source is hosted on GitHub and the gem itself is available, like any other, on rubygems.org.

Externally, little has changed. sudo gem install sql-logging (or put it in your Gemfile and bundle install), then restart your application., You’ll see additional information in your console: a count of rows returned by each SQL statement, a rough count of bytes in the response, a backtrace that shows you exactly what triggered the execution, and a top 10 list of the most time-consuming queries in each request.

I moved configuration out of the ActionController::Base class and into SqlLogging::Statistics, but the names are (mostly) the same. Check the README for details.