Sha256: 29217ac8a6cbb86b721e5e7b2b7dcfec84971f0d0666b574a2a1f220e84a67e8
Contents?: true
Size: 612 Bytes
Versions: 1
Compression:
Stored size: 612 Bytes
Contents
# frozen_string_literal: true require "time" class Yog # https://brandur.org/logfmt module Logfmt 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 Numeric v.to_s when String (/[ '",{}\[\]:=]/ =~ v) ? v.inspect : v else render(v.to_s) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yog-0.2.0 | lib/yog/logfmt.rb |