Class: Lograge::Formatters::KeyValue
- Inherits:
-
Object
- Object
- Lograge::Formatters::KeyValue
- Defined in:
- lib/lograge/formatters/key_value.rb
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#call(data) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/lograge/formatters/key_value.rb', line 4 def call(data) fields = fields_to_display(data) event = fields.map { |key| format(key, data[key]) } event.join(' ') end |
#fields_to_display(data) ⇒ Object
11 12 13 |
# File 'lib/lograge/formatters/key_value.rb', line 11 def fields_to_display(data) data.keys end |
#format(key, value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lograge/formatters/key_value.rb', line 15 def format(key, value) if key == :error # Exactly preserve the previous output # Parsing this can be ambigious if the error messages contains # a single quote value = "'#{value}'" else # Ensure that we always have exactly two decimals value = Kernel.format('%.2f', value) if value.is_a? Float end "#{key}=#{value}" end |