Module: LogStruct::Log::Shared::MergeAdditionalDataFields

Constant Summary collapse

RESERVED_KEYS =

Reserved keys that cannot be overwritten by additional_data. These are the core log structure fields that must not be modified.

T.let(%i[src evt lvl ts].freeze, T::Array[Symbol])

Instance Method Summary collapse

Instance Method Details

#merge_additional_data_fields(hash) ⇒ void

This method returns an undefined value.

Parameters:

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


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/log_struct/shared/merge_additional_data_fields.rb', line 22

def merge_additional_data_fields(hash)
  ad = additional_data
  return unless ad
  ad.each do |key, value|
    sym_key = key.to_sym
    if RESERVED_KEYS.include?(sym_key)
      LogStruct.handle_exception(
        ArgumentError.new("additional_data attempted to overwrite reserved key: #{sym_key}"),
        source: Source::Internal
      )
      next
    end
    hash[sym_key] = value
  end
end