diff --git a/lib/fluent/compat/parser.rb b/lib/fluent/compat/parser.rb index af9bd61736..836ee1eeb9 100644 --- a/lib/fluent/compat/parser.rb +++ b/lib/fluent/compat/parser.rb @@ -18,6 +18,7 @@ require 'fluent/plugin/parser' require 'fluent/mixin' +require 'fluent/plugin/parser_regexp' require 'fluent/plugin/parser_json' require 'fluent/plugin/parser_tsv' require 'fluent/plugin/parser_ltsv' @@ -121,6 +122,22 @@ class TimeParser < Fluent::Plugin::Parser::TimeParser class RegexpParser < Fluent::Plugin::RegexpParser # TODO: warn when deprecated + def initialize(regexp, conf = {}) + super() + + unless conf.empty? + unless conf.is_a?(Config::Element) + conf = Config::Element.new('default_regexp_conf', '', conf, []) + end + configure(conf) + end + + @regexp = regexp + end + + def patterns + {'format' => @regexp, 'time_format' => @time_format} + end end class ValuesParser < Fluent::Plugin::ValuesParser diff --git a/lib/fluent/plugin/parser.rb b/lib/fluent/plugin/parser.rb index b3f085adc0..8faf713869 100644 --- a/lib/fluent/plugin/parser.rb +++ b/lib/fluent/plugin/parser.rb @@ -97,75 +97,6 @@ def parse(value) end end - class RegexpParser < Parser - include Fluent::TypeConverter - - config_param :time_key, :string, default: 'time' - config_param :time_format, :string, default: nil - - def initialize(regexp, conf={}) - super() - - unless conf.empty? - unless conf.is_a?(Config::Element) - conf = Config::Element.new('default_regexp_conf', '', conf, []) - end - configure(conf) - end - - @regexp = regexp - @time_parser = TimeParser.new(@time_format) - @mutex = Mutex.new - end - - def configure(conf) - super - @time_parser = TimeParser.new(@time_format) - end - - def patterns - {'format' => @regexp, 'time_format' => @time_format} - end - - def parse(text) - m = @regexp.match(text) - unless m - yield nil, nil - return - end - - time = nil - record = {} - - m.names.each do |name| - if value = m[name] - if name == @time_key - time = @mutex.synchronize { @time_parser.parse(value) } - if @keep_time_key - record[name] = if @type_converters.nil? - value - else - convert_type(name, value) - end - end - else - record[name] = if @type_converters.nil? - value - else - convert_type(name, value) - end - end - end - end - - if @estimate_current_event - time ||= Fluent::EventTime.now - end - - yield time, record - end - end - class ValuesParser < Parser include Fluent::TypeConverter diff --git a/lib/fluent/plugin/parser_apache.rb b/lib/fluent/plugin/parser_apache.rb index 607933a784..1973f9c653 100644 --- a/lib/fluent/plugin/parser_apache.rb +++ b/lib/fluent/plugin/parser_apache.rb @@ -16,9 +16,13 @@ require 'fluent/plugin/parser' -Fluent::Plugin.register_parser('apache', Proc.new{ - Fluent::Plugin::RegexpParser.new( - /^(?[^ ]*) [^ ]* (?[^ ]*) \[(?