lib/yog/logfmt.rb in yog-0.1.0 vs lib/yog/logfmt.rb in yog-0.2.0
- old
+ new
@@ -4,23 +4,29 @@
class Yog
# https://brandur.org/logfmt
module Logfmt
- def self.generate(**fields)
+ def self.generate(fields)
fields.map { |k, v| "#{k}=#{render(v)}" }.join(" ")
end
private
def self.render(v)
case v
+ when NilClass
+ "nil"
+ when TrueClass
+ "true"
+ when FalseClass
+ "false"
when DateTime, Time
v.iso8601(2)
when Float
sprintf("%.2f", v)
- when NilClass
- "nil"
+ when Numeric
+ v.to_s
when String
(/[ '",{}\[\]:=]/ =~ v) ? v.inspect : v
else
render(v.to_s)
end