Sha256: 985310a3c08f66bcad4d099fb77687790963e5c72871c7a331d818bbabee95a3

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

require 'rails/railtie'
require 'lograge'

module GetaroundUtils; end
module GetaroundUtils::Railties; end

class GetaroundUtils::Railties::Lograge < Rails::Railtie
  module LogrageActionController
    def append_info_to_payload(payload)
      super
      payload[:lograge] ||= {}
      payload[:lograge][:host] = request.host
      payload[:lograge][:params] = request.filtered_parameters.except(:action, :controller)
      payload[:lograge][:remote_ip] = request.remote_ip
      payload[:lograge][:user_agent] = request.user_agent
      payload[:lograge][:referer] = request.referer
      payload[:lograge][:controller_action] = "#{params[:controller]}##{params[:action]}" if defined?(params)
      payload[:lograge][:session_id] = session.is_a?(Hash) ? session[:id] : session.id if defined?(session)
      payload[:lograge][:user_id] = current_user&.id if defined?(current_user)
    end
  end

  initializer 'getaround_utils.action_controller' do
    ActionController::Base.prepend LogrageActionController
  end

  config.lograge.enabled = true
  config.lograge.custom_options = ->(event) { event.payload[:lograge] }
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
getaround_utils-0.2.11 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.2.10 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.2.9 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.2.7 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.2.6 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.2.5 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.2.1 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.2.0 lib/getaround_utils/railties/lograge.rb