Class: GetaroundUtils::LogFormatters::DeepKeyValue
- Inherits:
-
Utils::DeepKeyValueSerializer
- Object
- Utils::DeepKeyValueSerializer
- GetaroundUtils::LogFormatters::DeepKeyValue
- Defined in:
- lib/getaround_utils/log_formatters/deep_key_value.rb
Overview
Format logs using key=value notation
This logger leverage the fact that ruby Logger does not especially expect message to be string It will attempt to serialize message it is a string otherwise adding it as message=value
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Utils::DeepKeyValueSerializer
#flattify, #initialize, #serialize
Constructor Details
This class inherits a constructor from GetaroundUtils::Utils::DeepKeyValueSerializer
Class Method Details
.for_lograge ⇒ Object
35 36 37 |
# File 'lib/getaround_utils/log_formatters/deep_key_value.rb', line 35 def self.for_lograge new.extend(Lograge) end |
.for_sidekiq ⇒ Object
48 49 50 |
# File 'lib/getaround_utils/log_formatters/deep_key_value.rb', line 48 def self.for_sidekiq new.extend(Sidekiq) end |
Instance Method Details
#call(severity, _datetime, appname, message) ⇒ Object
23 24 25 26 |
# File 'lib/getaround_utils/log_formatters/deep_key_value.rb', line 23 def call(severity, _datetime, appname, ) payload = { severity: severity, appname: appname } "#{normalize(payload)} #{normalize()}\n" end |
#normalize(message) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/getaround_utils/log_formatters/deep_key_value.rb', line 13 def normalize() if .is_a?(Hash) serialize(.compact) elsif .is_a?(String) && .match(/^[^ =]+=/) else serialize(message: .to_s) end end |