class Fluent::TextFormatter::JSONFormatter

Public Instance Methods

configure(conf) click to toggle source
# File lib/fluent/formatter.rb, line 140
def configure(conf)
  super

  begin
    raise LoadError unless @json_parser == 'oj'
    require 'oj'
    Oj.default_options = Fluent::DEFAULT_OJ_OPTIONS
    @dump_proc = Oj.method(:dump)
  rescue LoadError
    @dump_proc = Yajl.method(:dump)
  end

  # format json is used on various highload environment, so re-define method to skip if check
  unless @add_newline
    define_singleton_method(:format, method(:format_without_nl))
  end
end
format_record(record) click to toggle source
# File lib/fluent/formatter.rb, line 158
def format_record(record)
  "#{@dump_proc.call(record)}\n"
end
format_without_nl(tag, time, record) click to toggle source
# File lib/fluent/formatter.rb, line 162
def format_without_nl(tag, time, record)
  @dump_proc.call(record)
end