DEV Community

Cover image for Lorgage - Taming Rails Logs (Video)
Mike Rogers ✈️
Mike Rogers ✈️

Posted on

Lorgage - Taming Rails Logs (Video)

I've love steaming through the Rails logs, they can help debug problems pretty quickly. However by default they're pretty verbose, which can make searching through & storing a bit tricky.

In this video, I go through the Lorgage gem for Ruby On Rails & show how it can be used to reduce your logs to one line per a request.

The code

To remove attributes from our log lines, we passed a lambda to config.lograge.custom_options.

# config/initializers/lograge.rb
Rails.application.configure do
  config.lograge.enabled = true
  config.lograge.custom_options = lambda do |event|
    exceptions = %w[controller action]

    {
      params: event.payload[:params].except(*exceptions)
    }
  end
end
Enter fullscreen mode Exit fullscreen mode

To filter parameters (replace them with "[FILTERED]") from our logs we added them to the filter_parameters config option:

# config/initializers/filter_parameter_logging.rb
Rails.application.config.filter_parameters += [:password, :secret_pass]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)