Skip to content

Instantly share code, notes, and snippets.

@rdavila
Created September 5, 2011 20:25
Show Gist options
  • Save rdavila/1195843 to your computer and use it in GitHub Desktop.
Save rdavila/1195843 to your computer and use it in GitHub Desktop.
sql logger
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