How can you hide database output in Rails console?

Ruby on-Rails

Ruby on-Rails Problem Overview


In newer version of Rails, I'm guessing from 3 up, database queries are output to the console. This is useful most of the time, but how can you hide it when you do not want to see it?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

A better way of doing this is by typing this into the console:

ActiveRecord::Base.logger.level = 1 

as it prevents problems trying use a pointer to a logger that is set to nil (source: https://stackoverflow.com/questions/7759321/disable-rails-3-1-sql-logging)

To turn it back on

ActiveRecord::Base.logger.level = 0

Solution 2 - Ruby on-Rails

ActiveRecord::Base.logger = nil

from here

Solution 3 - Ruby on-Rails

Short answer... In the file development.rb change or add the value of config.log_level so that there's a line like

config.log_level = :info

Solution 4 - Ruby on-Rails

From a friend of mine:

your_query; nil

Solution 5 - Ruby on-Rails

In Rails 3.2, setting

config.logger.level = Logger::INFO

worked fine for me for turning off SQL output.

Solution 6 - Ruby on-Rails

I see you already got your needed answer although I would like to advise the 'quiet assets' gem to you, most of the log data will be asset compiling and inclusions, this gem will remove that and still output the queries and data behavior.

Have fun

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRoger ErtesvagView Question on Stackoverflow
Solution 1 - Ruby on-RailsAaron B. RussellView Answer on Stackoverflow
Solution 2 - Ruby on-RailssamvermetteView Answer on Stackoverflow
Solution 3 - Ruby on-Railsmadth3View Answer on Stackoverflow
Solution 4 - Ruby on-RailstatiCarvalhoView Answer on Stackoverflow
Solution 5 - Ruby on-RailsbrokenbeatnikView Answer on Stackoverflow
Solution 6 - Ruby on-RailsdennisView Answer on Stackoverflow