Logging ONLY SQL in your rails console

Say you’re interested in ONLY debugging some SQL.

But your rails console is spitting out GETs for assets.

Here’s one way to disable logging of the asset pipeline. Place the following code in config/initializers/quiet_assets.rb

if Rails.env.development?

  Rails.application.assets.logger = Logger.new(‘/dev/null’)

  Rails::Rack::Logger.class_eval do

    def call_with_quiet_assets(env)

      previous_level = Rails.logger.level

      Rails.logger.level = Logger::ERROR if env[‘PATH_INFO’] =~ %r{^/assets/}



      Rails.logger.level = previous_level


    alias_method_chain :call, :quiet_assets



Also works with Rails 4 (although you need to create the file).

See also:


and a possibly better way via a Rack middleware:


Note, in development.rb there’s a

config.assets.debug = true

which you can set to false. This reduces most of the 304’s for the asset pipeline but you still get the application css and js files being logged.

Obviously another way of doing this (and possibly the easiest) is to just do:

tail -f development.log | grep -v “asset”

Leave a Reply

Your email address will not be published. Required fields are marked *