module Flog::ParamsFormattable

ParamsFormattable enables to format request parameters in log.

Public Instance Methods

start_processing(event) click to toggle source
Calls superclass method
# File lib/flog/params_formattable.rb, line 27
def start_processing(event)
  return super(event) unless formattable?(event)

  replaced = replace_params(event.payload[:params])

  shunt_payload_value(event.payload, :params, replaced) do
    super(event)
  end
end

Private Instance Methods

force_format_by_nested_params?(event) click to toggle source
# File lib/flog/params_formattable.rb, line 56
def force_format_by_nested_params?(event)
  return false unless Flog.config.force_on_nested_params?

  event.payload[:params].values.any? { |value| value.is_a?(Hash) }
end
formattable?(event) click to toggle source
# File lib/flog/params_formattable.rb, line 47
def formattable?(event)
  return false if Flog.config.ignore_params?
  return false unless Flog::Status.params_formattable?

  return true if force_format_by_nested_params?(event)

  key_count_over?(event)
end
key_count_over?(event) click to toggle source
# File lib/flog/params_formattable.rb, line 62
def key_count_over?(event)
  threshold = Flog.config.params_key_count_threshold.to_i
  params = event.payload[:params].except(*ActionController::LogSubscriber::INTERNAL_PARAMS)
  params.keys.size > threshold
end
replace_params(params) click to toggle source
# File lib/flog/params_formattable.rb, line 39
def replace_params(params)
  return params if params.empty? || !params.respond_to?(:ai)

  replaced = params.dup
  replaced.singleton_class.prepend(ParamsExceptOverridable)
  replaced
end