Created
September 5, 2011 20:25
-
-
Save rdavila/1195843 to your computer and use it in GitHub Desktop.
sql logger
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
ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do | |
def log_with_syspanel_logger(sql, name, &block) | |
if Thread.current["syspanel.sql.logger.enabled"] | |
Thread.current["syspanel.sql.logger.enabled"] = false | |
SyspanelSqlLog.create(:sql => sql, :name => name) | |
end | |
log_without_syspanel_logger(sql, name, &block) | |
end | |
alias_method_chain :log, :syspanel_logger | |
end | |
class SyspanelSqlLogger | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
if env['REQUEST_URI'] =~ /syspanel/ | |
Thread.current["syspanel.sql.logger.enabled"] = true | |
end | |
@app.call(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment