Hide database queries in Rails console

Most of the time I think it’s useful to see what database queries your commands are generating in the Rails console. The rest of the time the output gets in the way by spamming your console output. It is really easy to turn this logging on and off from inside the console, just run the following command when you want to silence the output:

ActiveRecord::Base.logger.level = 1

This will set the logger’s level to INFO. Then to turn it back on enter:

ActiveRecord::Base.logger.level = 0

This will set the logger’s level back to DEBUG.