Sha256: 19bccc611fbae04706619fdfeee6ff402958dcd7b110ca529d047a9f46890138

Contents?: true

Size: 974 Bytes

Versions: 16

Compression:

Stored size: 974 Bytes

Contents

# frozen_string_literal: true

module Ougai
  # The features for JSON formatter
  # @attr [Boolean] jsonize Whether log should converts JSON
  # @attr [Boolean] with_newline Whether tailing NL should be appended
  module Formatters::ForJson
    attr_accessor :jsonize, :with_newline

    protected

    def init_opts_for_json(opts)
      @jsonize = opts.fetch(:jsonize, true)
      @with_newline = opts.fetch(:with_newline, true)
      @serializer = Ougai::Serializer.for_json
    end

    def to_level(severity)
      case severity
      when 'TRACE'
        10
      when 'DEBUG'
        20
      when 'INFO'
        30
      when 'WARN'
        40
      when 'ERROR'
        50
      when 'FATAL'
        60
      else
        70
      end
    end

    # requires convert_time(data) method
    def dump(data)
      return data unless @jsonize
      convert_time(data)
      str = @serializer.serialize(data)
      str << "\n" if @with_newline
      str
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ougai-2.0.0-java lib/ougai/formatters/for_json.rb
ougai-2.0.0 lib/ougai/formatters/for_json.rb
ougai-1.9.1-java lib/ougai/formatters/for_json.rb
ougai-1.9.1 lib/ougai/formatters/for_json.rb
ougai-1.9.0-java lib/ougai/formatters/for_json.rb
ougai-1.9.0 lib/ougai/formatters/for_json.rb
ougai-1.8.5 lib/ougai/formatters/for_json.rb
ougai-1.8.4 lib/ougai/formatters/for_json.rb
ougai-1.8.3 lib/ougai/formatters/for_json.rb
ougai-1.8.2 lib/ougai/formatters/for_json.rb
ougai-1.8.1 lib/ougai/formatters/for_json.rb
ougai-1.8.0-java lib/ougai/formatters/for_json.rb
ougai-1.8.0 lib/ougai/formatters/for_json.rb
ougai-1.7.1 lib/ougai/formatters/for_json.rb
ougai-1.7.1-java lib/ougai/formatters/for_json.rb
ougai-1.7.0 lib/ougai/formatters/for_json.rb