Class: Lograge::Formatters::KeyValue
- Inherits:
-
Object
- Object
- Lograge::Formatters::KeyValue
- Defined in:
- lib/lograge/formatters/key_value.rb
Constant Summary collapse
- LOGRAGE_FIELDS =
[ :method, :path, :format, :controller, :action, :status, :error, :duration, :view, :db, :location ]
Instance Method Summary collapse
Instance Method Details
#call(data) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lograge/formatters/key_value.rb', line 9 def call(data) fields = LOGRAGE_FIELDS fields += (data.keys - LOGRAGE_FIELDS) event = fields.inject([]) do |, key| next unless data.has_key?(key) # Exactly preserve the previous output # Parsing this can be ambigious if the error messages contains # a single quote data[key] = "'#{data[key]}'" if key == :error # Ensure that we always have exactly two decimals data[key] = "%.2f" % data[key] if data[key].is_a? Float << "#{key}=#{data[key]}" end event.join(" ") end |