Last active
March 10, 2017 11:31
-
-
Save tomajask/b804d707eecbd155f936ce5a2eb9b78b to your computer and use it in GitHub Desktop.
Add 'remote_ip' to lograge logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/application_controller.rb | |
class ApplicationController < ActionController::Base | |
def append_info_to_payload(payload) | |
super | |
payload[:remote_ip] = request.remote_ip | |
end | |
end | |
# config/environments/<your env>.rb | |
Rails.application.configure do | |
config.lograge.enabled = true | |
config.lograge.custom_options = lambda do |event| | |
options = { params: event.payload[:params].reject { |k| %w(controller action).include? k } } | |
options[:ip] = event.payload[:remote_ip] | |
options | |
end | |
end | |
# server logs | |
method=GET path=/notifications format=json controller=NotificationsController action=index status=200 duration=50.79 view=8.02 db=3.02 params={} ip=127.0.0.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment