Sha256: 0dc59cc88a5762fbcb23cf67752a1aab7adc2d59fd22ab87d6401b9e237c4b8b

Contents?: true

Size: 798 Bytes

Versions: 23

Compression:

Stored size: 798 Bytes

Contents

require 'json'

module RooOnRails
  # A generator for the logfmt log format.
  #
  # @see https://brandur.org/logfmt The original description of logfmt
  # @see https://godoc.org/github.com/kr/logfmt The 'reference' parser
  module Logfmt
    class << self
      def dump(hash)
        return nil if hash.nil? || hash.empty?

        hash.map { |k, v| "#{k}=#{dump_value(v)}" }.join(' ')
      end

      private

      def dump_value(v)
        str = case v
              when String then v
              when Symbol then v.to_s
              when Array, Hash then JSON.dump(v)
              else v.respond_to?(:to_json) ? v.to_json : v.inspect
              end

        @_escape_re ||= /[[:space:]"']/
        return str unless @_escape_re =~ str
        str.inspect
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
roo_on_rails-2.2.2 lib/roo_on_rails/logfmt.rb
roo_on_rails-2.2.1 lib/roo_on_rails/logfmt.rb
roo_on_rails-2.2.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-2.1.2 lib/roo_on_rails/logfmt.rb
roo_on_rails-2.1.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-2.0.0.pre.pre.2 lib/roo_on_rails/logfmt.rb
roo_on_rails-2.0.0.pre.pre.1 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.22.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.21.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.20.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.19.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.18.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.17.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.16.2 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.16.1 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.16.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.15.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.14.0 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.13.1 lib/roo_on_rails/logfmt.rb
roo_on_rails-1.13.0 lib/roo_on_rails/logfmt.rb