How to disable SQL Rails logs?

Is there a way to disable SQL logs in Rails, besides changing the log level? I have some logger.debug statements that I would like to print in my ActiveRecord models, but I want to hide the SQL statements.

+6
ruby-on-rails
source share
3 answers

You can execute moneky-patch, put it in a file, for example config/initializers/disable_ar_logging.rb :

 class ActiveRecord::ConnectionAdapters::AbstractAdapter def log_info(*args); end end 
+4
source share

Dan

Is it in production or development mode? If this is a development mode, this is usually what I do:

 logger.info("DEBUG my message here") logger.info("DEBUG #{my_object.inspect}") tail -f log/development | grep DEBUG 
+1
source share

Here is what worked for me in Rails 3.0.5:

  class ActiveRecord::ConnectionAdapters::AbstractAdapter def log(sql, name) name ||= "SQL" yield rescue Exception => e message = "#{e.class.name}: #{e.message}: #{sql}" @logger.debug message if @logger raise translate_exception(e, message) end end 

This is this method with a line that writes to the log. Attempts to cache SQL are still displayed in the log, and I have not figured out how to disable them.

+1
source share

All Articles