Class: Fluent::Plugin::JSONParser
- Defined in:
- lib/fluent/plugin/parser_json.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Parser
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes inherited from Parser
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Parser
Methods included from TimeMixin::Parser
Methods included from OwnedByMixin
Methods inherited from Base
#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #has_router?, #initialize, #inspect, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #terminate, #terminated?
Methods included from SystemConfig::Mixin
#system_config, #system_config_override
Methods included from Configurable
#config, included, #initialize, lookup_type, register_type
Constructor Details
This class inherits a constructor from Fluent::Plugin::Parser
Instance Method Details
#configure(conf) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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. = 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) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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.}" 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 |