class Fluent::Plugin::JSONParser
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
Fluent::Plugin::Base#configure
# File lib/fluent/plugin/parser_json.rb, line 31 def configure(conf) super if @time_format @time_parser = time_parser_create @mutex = Mutex.new end begin raise LoadError unless @json_parser == 'oj' require 'oj' Oj.default_options = Fluent::DEFAULT_OJ_OPTIONS @load_proc = Oj.method(:load) @error_class = Oj::ParseError rescue LoadError @load_proc = Yajl.method(:load) @error_class = Yajl::ParseError end end
parse(text) { |time, record| ... }
click to toggle source
# File lib/fluent/plugin/parser_json.rb, line 51 def parse(text) record = @load_proc.call(text) value = @keep_time_key ? record[@time_key] : record.delete(@time_key) if value if @time_format time = @mutex.synchronize { @time_parser.parse(value) } else begin time = Fluent::EventTime.from_time(Time.at(value.to_f)) rescue => e raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}" end end else if @estimate_current_event time = Fluent::EventTime.now else time = nil end end yield time, record rescue @error_class yield nil, nil end