Andrew Lindner     Blog     Archive     Reading     About

Quiet Those Noisy Logs

Have you ever wasted time sifting through log messages to find the useful information? The Silencer Ruby gem allows you to suppress logging for specified actions and quickly identify the signals hidden within the noise. This can be incredibly useful when you have a long running processing that produces log messages but does not provide any valuable information.


INSTALLATION

As with most gems, the installation is relatively straightforward.

Add the following line to your Gemfile:

gem 'silencer'

Then, install the gem:

bundle install

SAMPLE USE

Create a new file in your config/initializers folder named silencer.rb

Lastly, require the gem and add code along these lines:

require 'silencer/logger'

Rails.application.configure do
  config.middleware.swap(
    Rails::Rack::Logger,
    Silencer::Logger,
    silence: ['/annoying_action']
  )
end

The above will silence the logging any request made to the /annoying_action endpoint. You can substitute silence for get, post, or other HTTP verbs to quiet specific requests.


SOURCES

Documentation