Class: Fluent::TextParser::WithExtraFieldsParser
- Inherits:
-
Parser
- Object
- Parser
- Fluent::TextParser::WithExtraFieldsParser
- Defined in:
- lib/fluent/plugin/parser_with_extra_fields.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ WithExtraFieldsParser
constructor
A new instance of WithExtraFieldsParser.
- #parse(text) {|nil, nil| ... } ⇒ Object
Constructor Details
#initialize ⇒ WithExtraFieldsParser
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
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.}" unless @suppress_parse_error_log end yield nil, nil end |