Freenerd
Disable logger in Rails & Rspec

Parts of my Rails code have a good portion of logging code, because I want to observe it’s behavior closely in the real world. I will probably remove the logging code, once I’m confident enough with the code

But during testing these log lines distract me from the test results and hide other stuff. So I decided it is better to disable it. I did this by adding the following code to /config/environments/test.rb

# disable logger
class EmptyLogger < StringIO
  def write(input)
    # do nothing
  end
end
config.logger = Logger.new(EmptyLogger.new)

This writes all log messages to a StringIO object, which does nothing with it …