class Lograge::Formatters::LTSV
Public Instance Methods
call(data)
click to toggle source
# File lib/lograge/formatters/ltsv.rb, line 4 def call(data) fields = fields_to_display(data) event = fields.map { |key| format(key, data[key]) } event.join("\t") end
fields_to_display(data)
click to toggle source
# File lib/lograge/formatters/ltsv.rb, line 11 def fields_to_display(data) data.keys end
format(key, value)
click to toggle source
# File lib/lograge/formatters/ltsv.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 = "'#{escape value}'" elsif value.is_a? Float value = Kernel.format('%.2f', value) end "#{key}:#{value}" end
Private Instance Methods
escape(string)
click to toggle source
# File lib/lograge/formatters/ltsv.rb, line 30 def escape(string) value = string.is_a?(String) ? string.dup : string.to_s value.gsub!('\\', '\\\\') value.gsub!('\n', '\\n') value.gsub!('\r', '\\r') value.gsub!('\t', '\\t') value end