Class: Fluent::Plugin::SerializeJSONParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/fluent/plugin/parser_serialize_nested_json.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/fluent/plugin/parser_serialize_nested_json.rb', line 14

def configure(conf)
  if conf.has_key?('time_format')
    conf['time_type'] ||= 'string'
  end

  super
end

#parse(text) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fluent/plugin/parser_serialize_nested_json.rb', line 22

def parse(text)
  record = Yajl.load(text)

  values = Hash.new

  record.each do |k, v|
    next if @exclude.include?(k.to_s)

    if v.is_a?(Hash) || v.is_a?(Array)
      begin
        values[k] = Yajl::Encoder.encode(v)
        record.delete k
      rescue Exception => e
        # continue
      end
    end
    if v.is_a?(Numeric) && @strinfify_num == true
      begin
        values[k] = v.to_s
        record.delete k
      rescue Exception => e
      end
    end
  end
  record.merge!(values)

  time, record = convert_values(parse_time(record), record)

  yield time, record
rescue Yajl::ParseError
  yield nil, nil
end