SQL Logging to script/console

When running a Rails console session, a true time saver is directing the ActiveRecord logs to STDOUT instead of the log file.  This is easily accomplished adding the following to your ~/.irbrc file:

if rails_env = ENV['RAILS_ENV']
  # Called after the irb session is initialized and Rails has
  # been loaded (props: Mike Clark).
  IRB.conf[:IRB_RC] = Proc.new do
    ActiveRecord::Base.logger = Logger.new(STDOUT)
    ActiveRecord::Base.instance_eval { alias :[] :find }
  end
end

If someone knows the original author of these lines, let me know and I’ll give them proper attribution.

This entry was posted in Technology and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">