Sha256: b46c0045f3271d182ce457173c17886253b38844086dffe4d7b945423f0165c1
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
module GetaroundUtils; end module GetaroundUtils::LogFormatters; end require 'getaround_utils/utils/deep_key_value_serializer' class GetaroundUtils::LogFormatters::DeepKeyValue < GetaroundUtils::Utils::DeepKeyValueSerializer def normalize(message) if message.is_a?(Hash) serialize(message.compact) elsif message.is_a?(String) && message.match(/^[^ =]+=/) message else serialize(message: message.to_s) end end def call(severity, _datetime, appname, message) payload = { severity: severity, appname: appname } "#{normalize(payload)} #{normalize(message)}\n" end module Lograge def call(message) message = message.compact if message.is_a?(Hash) serialize(message) end end def self.for_lograge new.extend(Lograge) end module Sidekiq def sidekiq_context context = Thread.current&.fetch(:sidekiq_context, nil) context.is_a?(Hash) ? context : {} end def sidekiq_tid Thread.current&.fetch('sidekiq_tid', nil) || (Thread.current&.object_id ^ ::Process.pid).to_s(36) end def call(severity, _datetime, appname, message) payload = { severity: severity, appname: appname } sidekiq = sidekiq_context.merge(tid: sidekiq_tid).compact "#{normalize(payload)} #{normalize(message)} #{normalize(sidekiq: sidekiq)}\n" end end def self.for_sidekiq new.extend(Sidekiq) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
getaround_utils-0.1.11 | lib/getaround_utils/log_formatters/deep_key_value.rb |