How to Ruby logo

How to remove select statements from Rails logger output

26 Aug 2022

In development the number of SELECT queries usually takes a lot of space of the total request output. Unless you’re specifically optimising those, it’s much cleaner to remove them. Only a few lines in development.rb

Take a peak at ActiveRecord::LogSubscriber to see what we’re overriding.

# config/environments/development.rb

module LoggerWithoutSelect
  def sql(event)
    super unless event.payload[:sql].present? && event.payload[:sql].include?("SELECT")

ActiveRecord::LogSubscriber.prepend LoggerWithoutSelect

Well, that’s it, simple and effective! 😊