[Ruby] Show SQL for Active Record

James Moore banshee at banshee.com
Mon Jan 29 20:54:19 PST 2007


It's also easy to modify the logs to show you where the sql is coming from.
I stick something like this in my test directory (for debugging purposes,
not for actual testing):

#####################################
# To use this logger (with stacktrace):
#
# require Pathname.new(__FILE__).dirname + 'logger_change'


def dbg *args
    stack = caller(1).slice(0, 4)
    pp(*args)
    pp stack
end

class Logger
  def format_message(severity, timestamp, progname, msg)
       # dbg 'loginfo', msg, severity, timestamp, progname if msg =~
/INSERT.*s2_test_sui/
       dbg 'loginfo', msg, severity, timestamp, progname
  end
end
#####################################

And I tend to change it all the time it to do things like only print to the
logs if the sql matches a particular regex, change the slice size for the 
stack, etc.  It's more like a debugger macro than actual code. 

 - James



More information about the Ruby mailing list