How to add the request parameters along with in lograge outputted files

Here is how to include the request parameters n lograge formatted log files.
Lograge is a RubyGem that modifies the rails log format for you so it’s easier to parse by parsers like Logstash, for example.

Here is what needs to be added to each file:

Gemfile:

gem "lograge"

config/environments/production.rb

MyApp::Application.configure do
config.lograge.enabled = true

# custom_options can be a lambda or hash
# if it's a lambda then it must return a hash
  config.lograge.custom_options = lambda do |event|
    unwanted_keys = %w[format action controller]
    params = event.payload[:params].reject { |key,_| unwanted_keys.include? key }

    # capture some specific timing values you are interested in
    {:params => params }
  end

app/controllers/application_controller.rb

def append_info_to_payload(payload)
super
payload["params"] = request.params
end
VN:F [1.9.22_1171]
Rating: 5.0/5 (3 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)
How to add the request parameters along with in lograge outputted files, 5.0 out of 5 based on 3 ratings
Facebook Twitter Email

One Comment to “How to add the request parameters along with in lograge outputted files”