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
-
#as_json(options = nil) ⇒ Hash{String => T.untyped}
Override as_json to use our custom serialize method instead of default T::Struct serialization.
-
#serialize_common(strict = true) ⇒ Hash{Symbol => T.untyped}
Convert the log entry to a hash for serialization.
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
30 31 32 33 |
# File 'lib/log_struct/log/shared/serialize_common.rb', line 30 def as_json( = 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)
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) => .iso8601(3) } end |