Module: LogStruct::Log::AddRequestFields

Extended by:
T::Helpers, T::Sig
Included in:
Request, Security
Defined in:
lib/log_struct/log/shared/add_request_fields.rb

Overview

Common log serialization method

Instance Method Summary collapse

Instance Method Details

#add_request_fields(hash) ⇒ void

This method returns an undefined value.

Helper method to serialize request fields

Parameters:

  • hash (Hash{Symbol => T.untyped})


18
19
20
21
22
23
24
25
26
# File 'lib/log_struct/log/shared/add_request_fields.rb', line 18

def add_request_fields(hash)
  # Add request-specific fields if they're present
  hash[LOG_KEYS.fetch(:path)] = path if path
  hash[LOG_KEYS.fetch(:http_method)] = http_method if http_method # Use `method` in JSON
  hash[LOG_KEYS.fetch(:source_ip)] = source_ip if source_ip
  hash[LOG_KEYS.fetch(:user_agent)] = user_agent if user_agent
  hash[LOG_KEYS.fetch(:referer)] = referer if referer
  hash[LOG_KEYS.fetch(:request_id)] = request_id if request_id
end