Module: LogStruct::Log::Shared::SerializeCommon
- Extended by:
- T::Helpers, T::Sig
- Included in:
- ActionMailer::Delivered, ActionMailer::Delivery, ActionMailer::Error, ActiveJob::Enqueue, ActiveJob::Finish, ActiveJob::Schedule, ActiveJob::Start, ActiveModelSerializers, ActiveStorage::Delete, ActiveStorage::Download, ActiveStorage::Exist, ActiveStorage::Metadata, ActiveStorage::Stream, ActiveStorage::Upload, ActiveStorage::Url, Ahoy, CarrierWave::Delete, CarrierWave::Download, CarrierWave::Upload, Dotenv::Load, Dotenv::Restore, Dotenv::Save, Dotenv::Update, Error, GoodJob::Enqueue, GoodJob::Error, GoodJob::Finish, GoodJob::Log, GoodJob::Schedule, GoodJob::Start, Plain, Puma::Shutdown, Puma::Start, Request, LogStruct::Log::SQL, LogStruct::Log::Security::BlockedHost, LogStruct::Log::Security::CSRFViolation, LogStruct::Log::Security::IPSpoof, LogStruct::Log::Shrine::Delete, LogStruct::Log::Shrine::Download, LogStruct::Log::Shrine::Exist, LogStruct::Log::Shrine::Metadata, LogStruct::Log::Shrine::Upload, LogStruct::Log::Sidekiq
- Defined in:
- lib/log_struct/shared/serialize_common.rb
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Hash{String => T.untyped}
- #serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
- #serialize_common(strict = true) ⇒ Hash{Symbol => T.untyped}
Instance Method Details
#as_json(options = nil) ⇒ Hash{String => T.untyped}
58 59 60 |
# File 'lib/log_struct/shared/serialize_common.rb', line 58 def as_json( = nil) serialize.transform_keys(&:to_s) end |
#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/log_struct/shared/serialize_common.rb', line 18 def serialize(strict = true) # Start with shared fields (source, event, level, timestamp) out = serialize_common(strict) # Merge event/base fields from the struct-specific hash kernel_self = T.cast(self, Kernel) field_hash = T.cast(kernel_self.public_send(:to_h), T::Hash[LogStruct::LogField, T.untyped]) field_hash.each do |log_field, value| next if value.nil? key = log_field.serialize # Limit backtrace to first 5 lines if key == :backtrace && value.is_a?(Array) value = value.first(5) end out[key] = value.is_a?(::Time) ? value.iso8601 : value end # Merge any additional_data at top level if available if kernel_self.respond_to?(:merge_additional_data_fields) # merge_additional_data_fields expects symbol keys merge_target = T.cast(self, LogStruct::Log::Shared::MergeAdditionalDataFields) merge_target.merge_additional_data_fields(out) end out end |
#serialize_common(strict = true) ⇒ Hash{Symbol => T.untyped}
48 49 50 51 52 53 54 55 |
# File 'lib/log_struct/shared/serialize_common.rb', line 48 def serialize_common(strict = true) { LogField::Source.serialize => source.serialize.to_s, LogField::Event.serialize => event.serialize.to_s, LogField::Level.serialize => level.serialize.to_s, LogField::Timestamp.serialize => .iso8601(3) } end |