Skip to content

Instantly share code, notes, and snippets.

@letronje
Created May 6, 2013 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letronje/5523716 to your computer and use it in GitHub Desktop.
Save letronje/5523716 to your computer and use it in GitHub Desktop.
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter
if defined?(Rails)
LOGGER_REGEXP = /^#{Rails.root}(?!\/vendor\/rails)/
def query_with_extra_logging(*args) #:nodoc:
if ActiveRecord::Base.enable_extended_logging && Rails.logger && Rails.logger.level == Logger::DEBUG
sql = args.first
unless (sql =~ /(pg_get_constraintdef|pg_attribute|pg_class)/)
Rails.logger.debug
Rails.logger.debug(caller.select { |x|
ActiveRecord::Base.enable_really_extended_logging || x.match(LOGGER_REGEXP)
}.join("\n"))
end
end
query_without_extra_logging(*args)
end
alias_method_chain :query, :extra_logging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment