Sha256: 9bff38b3dfb7bf93412905156a5dd94f0d77277919b390850a9a636e4d6710f2

Contents?: true

Size: 655 Bytes

Versions: 14

Compression:

Stored size: 655 Bytes

Contents

module Lograge
  module Formatters
    class KeyValue
      def call(data)
        fields = fields_to_display(data)

        event = fields.map { |key| format(key, data[key]) }
        event.join(' ')
      end

      def fields_to_display(data)
        data.keys
      end

      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}'"
        elsif value.is_a? Float
          value = Kernel.format('%.2f', value)
        end

        "#{key}=#{value}"
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lograge-0.9.0 lib/lograge/formatters/key_value.rb
lograge-0.8.0 lib/lograge/formatters/key_value.rb
lograge-0.7.1 lib/lograge/formatters/key_value.rb
lograge-0.7.0 lib/lograge/formatters/key_value.rb
lograge-0.6.0 lib/lograge/formatters/key_value.rb
lograge-0.5.1 lib/lograge/formatters/key_value.rb
lograge-0.5.0 lib/lograge/formatters/key_value.rb
lograge-0.5.0.rc2 lib/lograge/formatters/key_value.rb
lograge-0.5.0.rc1 lib/lograge/formatters/key_value.rb
lograge-0.4.1 lib/lograge/formatters/key_value.rb
lograge-0.4.0 lib/lograge/formatters/key_value.rb
lograge-0.4.0.rc2 lib/lograge/formatters/key_value.rb
lograge-0.4.0.rc1 lib/lograge/formatters/key_value.rb
lograge-0.4.0.pre4 lib/lograge/formatters/key_value.rb