class Thrifty::Logger::LogfmtFormatter
Constants
- IGNORED_FIELDS
- UNESCAPED_STRING
Public Instance Methods
call(entry)
click to toggle source
# File lib/thrifty/logger/formatters/logfmt_formatter.rb, line 8 def call(entry) case entry when ExceptionEntry format_exception(entry) when Entry format_entry(entry) else [entry_or_ex.to_s] end end
Private Instance Methods
format_entry(entry)
click to toggle source
# File lib/thrifty/logger/formatters/logfmt_formatter.rb, line 21 def format_entry(entry) [format_hash(entry.to_h)] end
format_exception(entry)
click to toggle source
# File lib/thrifty/logger/formatters/logfmt_formatter.rb, line 25 def format_exception(entry) values = [] values << format_hash(entry.to_h) if entry.exception && entry.exception.backtrace.is_a?(Array) values << "#{entry.exception.class}: #{entry.exception.message}\n" + entry.exception.backtrace.map{|l| "\t#{l}" }.join("\n") end values end
format_hash(attrs)
click to toggle source
# File lib/thrifty/logger/formatters/logfmt_formatter.rb, line 36 def format_hash(attrs) attrs.inject([]) do |ac, (k,v)| if !IGNORED_FIELDS.include?(k) && !(v == nil || v == "") new_value = sanitize(v) ac << "#{k}=#{new_value}" end ac end.join(" ") end
may_quote(s)
click to toggle source
# File lib/thrifty/logger/formatters/logfmt_formatter.rb, line 67 def may_quote(s) s =~ UNESCAPED_STRING ? s : quote(s) end
quote(s)
click to toggle source
# File lib/thrifty/logger/formatters/logfmt_formatter.rb, line 63 def quote(s) s.inspect end
sanitize(v)
click to toggle source
# File lib/thrifty/logger/formatters/logfmt_formatter.rb, line 46 def sanitize(v) case v when ::Array may_quote v.join(",") when ::Integer, ::Symbol v.to_s when ::Float "%0.4f" % v when ::TrueClass, ::FalseClass v ? "t" : "f" when Time quote v.utc.to_s else may_quote(v.to_s) end end