Disable Rails SQL logging in console

gylaz picture gylaz · Oct 13, 2011 · Viewed 100.2k times · Source

Is there a way to disable SQL query logging when I'm executing commands in the console? Ideally, it would be great if I can just disable it and re-enable it with a command in the console.

I'm trying to debug something and using "puts" to print out some relevant data. However, the sql query output is making it hard to read.


Edit: I found another solution, since setting the logger to nil sometimes raised an error, if something other than my code tried to call logger.warn

Instead of setting the logger to nil you can set the level of the logger to 1.

ActiveRecord::Base.logger.level = 1 # or Logger::INFO

Answer

Ryan Bigg picture Ryan Bigg · Oct 13, 2011

To turn it off:

old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil

To turn it back on:

ActiveRecord::Base.logger = old_logger