Sha256: 7085b1613e6f3567bf63de0f8b901bc584fdc8c8fef050ff0d36acf8b983e092
Contents?: true
Size: 819 Bytes
Versions: 3
Compression:
Stored size: 819 Bytes
Contents
module Jersey class LogfmtLogger < BaseLogger private def unparse(attrs) attrs.map { |k, v| unparse_pair(k, v) }.compact.join(" ") end def quote_string(k, v) # try to find a quote style that fits if !v.include?('"') %{#{k}="#{v}"} elsif !v.include?("'") %{#{k}='#{v}'} else %{#{k}="#{v.gsub(/"/, '\\"')}"} end end def unparse_pair(k, v) v = v.call if v.is_a?(Proc) # only quote strings if they include whitespace if v == nil nil elsif v == true k elsif v.is_a?(Float) "#{k}=#{format("%.3f", v)}" elsif v.is_a?(String) && v =~ /\s/ quote_string(k, v) elsif v.is_a?(Time) "#{k}=#{v.iso8601}" else "#{k}=#{v}" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
jersey-0.2.0 | lib/jersey/logging/logfmt_logger.rb |
jersey-0.1.0 | lib/jersey/logging/logfmt_logger.rb |
jersey-0.0.3 | lib/jersey/logging/logfmt_logger.rb |