Created
January 7, 2013 14:59
-
-
Save davidrenne/4475557 to your computer and use it in GitHub Desktop.
log all queries to file in ruby/rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connection = ActiveRecord::Base.connection | |
class << connection | |
alias :original_exec :execute | |
def execute(sql, *name) | |
# try to log sql command but ignore any errors that occur in this block | |
# we log before executing, in case the execution raises an error | |
begin | |
file = File.open(Rails.root + "/log/database.log",'a'){|f| f.puts Time.now.to_s+": "+sql} | |
rescue Exception => e | |
; | |
end | |
# execute original statement | |
original_exec(sql, *name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment