Class: Fluent::TextParser::JSONParser
- Defined in:
- lib/fluent/parser.rb
Constant Summary
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes inherited from Parser
Instance Method Summary collapse
Methods inherited from Parser
Methods included from Configurable
#config, included, #initialize, lookup_type, register_type
Constructor Details
This class inherits a constructor from Fluent::Parser
Instance Method Details
#configure(conf) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/fluent/parser.rb', line 242 def configure(conf) super unless @time_format.nil? @time_parser = TimeParser.new(@time_format) @mutex = Mutex.new end begin raise LoadError unless @json_parser == 'oj' require 'oj' @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
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/fluent/parser.rb', line 261 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 = value.to_i rescue => e raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.}" end end else if @estimate_current_event time = Engine.now else time = nil end end if block_given? yield time, record else return time, record end rescue @error_class if block_given? yield nil, nil else return nil, nil end end |