Class: Fluent::TextParser::WithExtraFieldsParser

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

Instance Method Summary collapse

Constructor Details

#initializeWithExtraFieldsParser

Returns a new instance of WithExtraFieldsParser.



12
13
14
15
16
# File 'lib/fluent/plugin/parser_with_extra_fields.rb', line 12

def initialize
  super
  @parser = nil
  @extra_fields = {}
end

Instance Method Details

#configure(conf) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/fluent/plugin/parser_with_extra_fields.rb', line 18

def configure(conf)
  super
  @parser = Plugin.new_parser(@base_format)
  @parser.configure(conf)
  
  JSON.parse(conf["extra_fields"]).each { |k, v|
    @extra_fields[k] = v
  }
end

#parse(text) {|nil, nil| ... } ⇒ Object

Yields:

  • (nil, nil)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fluent/plugin/parser_with_extra_fields.rb', line 28

def parse(text)
  begin
    @parser.parse(text) { |time, record|
      if time && record
        @extra_fields.each { |k, v|
          record[k] = v
        }
        yield time, record
        return
      end
    }
  rescue => e
    $log.warn "parse failed #{e.message}" unless @suppress_parse_error_log
  end
  yield nil, nil
end