Sha256: de512cbf0302f2baf0f3206f0098ebaa52df622ce40fb574e306397ebb9facf4

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require 'rails/railtie'
require 'getaround_utils/log_formatters/deep_key_value'
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[:host] = request.host
      payload[:remote_ip] = request.remote_ip
      payload[:request_id] = request.uuid
      payload[:user_agent] = request.user_agent
      payload[:referer] = request.referer
      payload[:controller_action] = "#{params[:controller]}##{params[:action]}" if params
      payload[:session_id] = session&.id
      payload[: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.formatter = GetaroundUtils::LogFormatters::DeepKeyValue.new
  config.lograge.custom_options = lambda do |event|
    event.payload.except(:headers).compact
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
getaround_utils-0.1.2 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.1.1 lib/getaround_utils/railties/lograge.rb
getaround_utils-0.1.0 lib/getaround_utils/railties/lograge.rb