Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding documentation on how to enable param logging #68

Merged
merged 2 commits into from
Sep 17, 2014

Conversation

iloveitaly
Copy link
Collaborator

Some documentation to allow people new to lograge to quickly enable param logging in their apps.

@JacobEvelyn
Copy link

+1

@iloveitaly
Copy link
Collaborator Author

Here is some code to log parameters in addition to the request IP, user agent (using the browser gem), and the current_user if available.

# application_controller.rb

class ApplicationController < ActionController::Base

  def append_info_to_payload(payload)
    super

    payload[:ip] = request.remote_ip
    payload[:uid] = current_user.id if current_user
    payload[:ua] = browser.to_s
  end

end

# production.rb

  config.lograge.enabled = true
  config.lograge.custom_options = lambda do |event|
    payload = { "params" => event.payload[:params].except('controller', 'action') }
    payload.merge(event.payload.select { |k,v| [:ip, :uid, :ua].include?(k) && v.present? })
  end

@eric
Copy link

eric commented Aug 25, 2014

👍

@stve
Copy link

stve commented Aug 27, 2014

You could condense the example even further using Rails' Hash#slice!:

params = event.payload[:params].slice!('controller', 'action')
{ 'params' => params }


{ "params" => params }
end
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing an end to close the configure block.

@benlovell
Copy link
Collaborator

@iloveitaly get the small issue above resolved and I'll :shipit:

@iloveitaly
Copy link
Collaborator Author

Whoops, sorry about that! Fixed it up @benlovell

@benlovell
Copy link
Collaborator

@iloveitaly You da' man! Thanks ❤️

benlovell pushed a commit that referenced this pull request Sep 17, 2014
Adding documentation on how to enable param logging
@benlovell benlovell merged commit 9265850 into roidrage:master Sep 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants