Module: LogStruct::Log::SerializeCommon

Extended by:
T::Helpers, T::Sig
Included in:
ActionMailer, ActiveJob, ActiveStorage, CarrierWave, GoodJob, MergeAdditionalDataFields, Plain, Request, SQL, Security, Shrine, Sidekiq
Defined in:
lib/log_struct/log/shared/serialize_common.rb

Overview

Common log serialization method

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Hash{String => T.untyped}

Override as_json to use our custom serialize method instead of default T::Struct serialization

Parameters:

  • options (T.untyped) (defaults to: nil)

Returns:

  • (Hash{String => T.untyped})


30
31
32
33
# File 'lib/log_struct/log/shared/serialize_common.rb', line 30

def as_json(options = nil)
  # Convert symbol keys to strings for JSON
  serialize.transform_keys(&:to_s)
end

#serialize_common(strict = true) ⇒ Hash{Symbol => T.untyped}

Convert the log entry to a hash for serialization. (strict param is unused, but need same signature as default T::Struct.serialize)

Parameters:

  • strict (Boolean) (defaults to: true)

Returns:

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


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

def serialize_common(strict = true)
  {
    LOG_KEYS.fetch(:source) => source.serialize.to_s,
    LOG_KEYS.fetch(:event) => event.serialize.to_s,
    LOG_KEYS.fetch(:level) => level.serialize.to_s,
    LOG_KEYS.fetch(:timestamp) => timestamp.iso8601(3)
  }
end