lib/fluent/plugin/grok.rb in fluent-plugin-grok-parser-2.0.0 vs lib/fluent/plugin/grok.rb in fluent-plugin-grok-parser-2.0.1

- old
+ new

@@ -25,50 +25,50 @@ @multiline_mode = false @conf = conf if plugin.respond_to?(:firstline?) @multiline_mode = true end - if @conf['multiline_start_regexp'] - @multiline_start_regexp = Regexp.compile(@conf['multiline_start_regexp'][1..-2]) + if @conf["multiline_start_regexp"] + @multiline_start_regexp = Regexp.compile(@conf["multiline_start_regexp"][1..-2]) end end def add_patterns_from_file(path) File.new(path).each_line do |line| - next if line[0] == '#' || /^$/ =~ line + next if line[0] == "#" || /^$/ =~ line name, pat = line.chomp.split(/\s+/, 2) @pattern_map[name] = pat end end def setup - if @conf['grok_pattern'] - @parsers << expand_pattern_expression(@conf['grok_pattern'], @conf) + if @conf["grok_pattern"] + @parsers << expand_pattern_expression(@conf["grok_pattern"], @conf) else - grok_confs = @conf.elements.select {|e| e.name == 'grok'} + grok_confs = @conf.elements.select {|e| e.name == "grok"} grok_confs.each do |grok_conf| - @parsers << expand_pattern_expression(grok_conf['pattern'], grok_conf) + @parsers << expand_pattern_expression(grok_conf["pattern"], grok_conf) end end end private def expand_pattern_expression(grok_pattern, conf) regexp, types = expand_pattern(grok_pattern) $log.info "Expanded the pattern #{conf['grok_pattern']} into #{regexp}" - options = nil - if @multiline_mode - options = Regexp::MULTILINE - end unless types.empty? conf["types"] = types.map{|subname,type| "#{subname}:#{type}" }.join(",") end - TextParser::RegexpParser.new(Regexp.new(regexp, options), conf) + _conf = conf.merge("expression" => regexp, "multiline" => @multiline_mode) + config = Fluent::Config::Element.new("parse", nil, _conf, []) + parser = Fluent::Plugin::RegexpParser.new + parser.configure(config) + parser rescue GrokPatternNotFoundError => e raise e rescue => e - $log.error e.backtrace.join("\n") + $log.error(error: e) end def expand_pattern(pattern) # It's okay to modify in place. no need to expand it more than once. type_map = {}