Class: Kiev::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/kiev/config.rb

Constant Summary collapse

DEFAULT_LOG_REQUEST_CONDITION =
proc do |request, _response|
  !DEFAULT_LOG_REQUEST_REGEXP.match(request.path)
end
DEFAULT_LOG_REQUEST_ERROR_CONDITION =
proc do |_request, response|
  response.status != 404
end
DEFAULT_LOG_RESPONSE_BODY_CONDITION =
proc do |_request, response|
  !!(response.status >= 400 && response.status < 500 && response.content_type =~ DEFAULT_LOG_RESPONSE_BODY_REGEXP)
end
DEFAULT_LOG_REQUEST_BODY_CONDITION =
proc do |request, _response|
  !!(request.content_type =~ /(application|text)\/xml/)
end
DEFAULT_IGNORED_RACK_EXCEPTIONS =
%w(
  ActiveRecord::RecordNotFound
  Mongoid::Errors::DocumentNotFound
  Sequel::RecordNotFound
).freeze
FILTERED_PARAMS =
%w(
  client_secret
  token
  password
  password_confirmation
  old_password
  credit_card_number
  credit_card_cvv
  credit_card_holder
  credit_card_expiry_month
  credit_card_expiry_year
  CardNumber
  CardCVV
  CardExpires
).freeze
IGNORED_PARAMS =
(%w(
  controller
  action
  format
  authenticity_token
  utf8
  tempfile
) << :tempfile).freeze
DEFAULT_HTTP_PROPAGATED_FIELDS =
{
  tracking_id: "X-Tracking-Id",
  request_id: "X-Request-Id",
  request_depth: "X-Request-Depth",
  tree_path: "X-Tree-Path"
}.freeze
DEFAULT_PRE_RACK_HOOK =
proc do |env|
  Config.instance.http_propagated_fields.each do |key, http_key|
    Kiev[key] = Util.sanitize(env[Util.to_http(http_key)])
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/kiev/config.rb', line 109

def initialize
  @log_request_condition = DEFAULT_LOG_REQUEST_CONDITION
  @log_request_error_condition = DEFAULT_LOG_REQUEST_ERROR_CONDITION
  @log_response_body_condition = DEFAULT_LOG_RESPONSE_BODY_CONDITION
  @log_request_body_condition = DEFAULT_LOG_REQUEST_BODY_CONDITION
  @filtered_params = FILTERED_PARAMS
  @ignored_params = IGNORED_PARAMS
  @disable_default_logger = true
  @development_mode = false
  @ignored_rack_exceptions = DEFAULT_IGNORED_RACK_EXCEPTIONS.dup
  @logger = Kiev::Logger.new(STDOUT)
  @log_level = default_log_level
  @persistent_log_fields = []
  @pre_rack_hook = DEFAULT_PRE_RACK_HOOK
  @disable_filter_for_log_levels = []
  self.propagated_fields = {}
  update_logger_settings
end

Instance Attribute Details

#all_http_propagated_fieldsObject (readonly)

Returns the value of attribute all_http_propagated_fields.



100
101
102
# File 'lib/kiev/config.rb', line 100

def all_http_propagated_fields
  @all_http_propagated_fields
end

#all_jobs_propagated_fieldsObject (readonly)

Returns the value of attribute all_jobs_propagated_fields.



100
101
102
# File 'lib/kiev/config.rb', line 100

def all_jobs_propagated_fields
  @all_jobs_propagated_fields
end

#appObject

Returns the value of attribute app.



88
89
90
# File 'lib/kiev/config.rb', line 88

def app
  @app
end

#development_modeObject

Returns the value of attribute development_mode.



100
101
102
# File 'lib/kiev/config.rb', line 100

def development_mode
  @development_mode
end

#disable_default_loggerObject

Returns the value of attribute disable_default_logger.



88
89
90
# File 'lib/kiev/config.rb', line 88

def disable_default_logger
  @disable_default_logger
end

#disable_filter_for_log_levelsObject

Returns the value of attribute disable_filter_for_log_levels.



100
101
102
# File 'lib/kiev/config.rb', line 100

def disable_filter_for_log_levels
  @disable_filter_for_log_levels
end

#filtered_paramsObject

Returns the value of attribute filtered_params.



88
89
90
# File 'lib/kiev/config.rb', line 88

def filtered_params
  @filtered_params
end

#http_propagated_fieldsObject

Returns the value of attribute http_propagated_fields.



100
101
102
# File 'lib/kiev/config.rb', line 100

def http_propagated_fields
  @http_propagated_fields
end

#ignored_paramsObject

Returns the value of attribute ignored_params.



88
89
90
# File 'lib/kiev/config.rb', line 88

def ignored_params
  @ignored_params
end

#ignored_rack_exceptionsObject

Returns the value of attribute ignored_rack_exceptions.



88
89
90
# File 'lib/kiev/config.rb', line 88

def ignored_rack_exceptions
  @ignored_rack_exceptions
end

#jobs_propagated_fieldsObject

Returns the value of attribute jobs_propagated_fields.



100
101
102
# File 'lib/kiev/config.rb', line 100

def jobs_propagated_fields
  @jobs_propagated_fields
end

#log_levelObject

Returns the value of attribute log_level.



100
101
102
# File 'lib/kiev/config.rb', line 100

def log_level
  @log_level
end

#log_request_body_conditionObject

Returns the value of attribute log_request_body_condition.



88
89
90
# File 'lib/kiev/config.rb', line 88

def log_request_body_condition
  @log_request_body_condition
end

#log_request_conditionObject

Returns the value of attribute log_request_condition.



88
89
90
# File 'lib/kiev/config.rb', line 88

def log_request_condition
  @log_request_condition
end

#log_request_error_conditionObject

Returns the value of attribute log_request_error_condition.



88
89
90
# File 'lib/kiev/config.rb', line 88

def log_request_error_condition
  @log_request_error_condition
end

#log_response_body_conditionObject

Returns the value of attribute log_response_body_condition.



88
89
90
# File 'lib/kiev/config.rb', line 88

def log_response_body_condition
  @log_response_body_condition
end

#loggerObject (readonly)

Returns the value of attribute logger.



100
101
102
# File 'lib/kiev/config.rb', line 100

def logger
  @logger
end

#persistent_log_fieldsObject

Returns the value of attribute persistent_log_fields.



88
89
90
# File 'lib/kiev/config.rb', line 88

def persistent_log_fields
  @persistent_log_fields
end

#pre_rack_hookObject

Returns the value of attribute pre_rack_hook.



88
89
90
# File 'lib/kiev/config.rb', line 88

def pre_rack_hook
  @pre_rack_hook
end

Instance Method Details

#filter_enabled?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/kiev/config.rb', line 175

def filter_enabled?
  !disable_filter_for_log_levels.include?(log_level)
end

#log_path=(value) ⇒ Object



148
149
150
151
# File 'lib/kiev/config.rb', line 148

def log_path=(value)
  logger.path = value
  update_logger_settings
end

#propagated_fields=(value) ⇒ Object

shortcut



143
144
145
146
# File 'lib/kiev/config.rb', line 143

def propagated_fields=(value)
  self.http_propagated_fields = value
  self.jobs_propagated_fields = value.keys
end

#supported_log_levelsObject



171
172
173
# File 'lib/kiev/config.rb', line 171

def supported_log_levels
  SUPPORTED_LOG_LEVELS
end