Sha256: 970e43d5094d469857dec04656d69a84e190fba6592679e741ef8c383fe5c08f

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

module Fluent
  class ReemitOutput < Output
    Fluent::Plugin.register_output('reemit', self)

    # To support log_level option implemented by Fluentd v0.10.43
    unless method_defined?(:log)
      define_method("log") { $log }
    end

    def initialize
      super
      @match_cache = {}
    end

    def configure(conf)
      super
    end

    def emit(tag, es, chain)
      engine_emit(tag, es)
      chain.next
    rescue => e
      log.warn "reemit: #{e.class} #{e.message} #{e.backtrace.first}"
    end

    private

    # My Engine.emit
    def engine_emit(tag, es)
      target = @match_cache[tag]
      unless target
        target = engine_match(tag) || Fluent::EngineClass::NoMatchMatch.new
        @match_cache[tag] = target
      end
      target.emit(tag, es)
    end

    # My Engine.match
    def engine_match(tag)
      # @matches.find {|m| m.match(tag) } # original Engine.match
      Engine.matches.find {|m| ignore_self_match(m, tag) }
    end

    # Currently support only
    #
    # <match foo.bar>
    #   type reemit
    # </match>
    #
    # and
    #
    # <match foo.bar>
    #   type copy
    #   <store>
    #     type reemit
    #   </store>
    # </match>
    def ignore_self_match(m, tag)
      return false if m.output == self
      return false if m.output.kind_of?(MultiOutput) and m.output.outputs.include?(self)
      m.match(tag)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-reemit-0.0.3 lib/fluent/plugin/out_reemit.rb