Sha256: 8941884032c7ee25aa19f361d40b51fd972b59a31db6ee5d36044dfd81bcfc41

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

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][: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

  HTTP_PARAMS = [:method, :path, :host, :remote_ip,
                 :status, :duration, :location,
                 :user_agent, :referer].freeze

  config.lograge.enabled = true
  config.lograge.custom_options = ->(event) {
    event.payload[:lograge]
  }
  config.lograge.before_format = ->(data, _) {
    data.except(*HTTP_PARAMS).merge(http: data.slice(*HTTP_PARAMS))
  }
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
getaround_utils-0.2.14 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.2.13 lib/getaround_utils/railties/lograge.rb