Sha256: ca0ca9efbf29691ba82cb73b6157ceb23c805bf9f69ebb2c7ad84308662bc22e

Contents?: true

Size: 1.66 KB

Versions: 25

Compression:

Stored size: 1.66 KB

Contents

#
# Fluentd
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

require 'fluent/plugin/parser'

module Fluent
  module Plugin
    class RegexpParser < Parser
      Plugin.register_parser("regexp", self)

      config_param :expression, :string
      config_param :ignorecase, :bool, default: false
      config_param :multiline, :bool, default: false

      config_set_default :time_key, 'time'

      def configure(conf)
        super

        expr = if @expression[0] == "/" && @expression[-1] == "/"
                 @expression[1..-2]
               else
                 @expression
               end
        regexp_option = 0
        regexp_option |= Regexp::IGNORECASE if @ignorecase
        regexp_option |= Regexp::MULTILINE if @multiline
        @regexp = Regexp.new(expr, regexp_option)
      end

      def parse(text)
        m = @regexp.match(text)
        unless m
          yield nil, nil
          return
        end

        r = {}
        m.names.each do |name|
          if value = m[name]
            r[name] = value
          end
        end

        time, record = convert_values(parse_time(r), r)
        yield time, record
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
fluentd-0.14.25 lib/fluent/plugin/parser_regexp.rb
fluentd-1.0.0.rc1 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.24 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.23 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.23.rc1 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.22 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.22.rc2 lib/fluent/plugin/parser_regexp.rb
fluentd-hubspot-0.14.14.2 lib/fluent/plugin/parser_regexp.rb
fluentd-hubspot-0.14.14.1 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.22.rc1 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.21 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.20 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.20.rc1 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.19 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.18 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.17-x86-mingw32 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.17-x64-mingw32 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.17 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.16 lib/fluent/plugin/parser_regexp.rb
fluentd-0.14.15 lib/fluent/plugin/parser_regexp.rb