class Fluent::Plugin::ConditionalTagRewriteOutput

Plugin '@type conditional_tag_rewrite'

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_conditional_tag_rewrite.rb, line 47
def initialize
  super

  @router = router
  @and_conditions = []
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_conditional_tag_rewrite.rb, line 54
def configure(conf)
  super

  # create objects from configuration
  @ands.each do |and_condition|
    condition_list = and_condition.conditions.map { |c| Condition.new(record_accessor_create(c.key), c.pattern) }
    @and_conditions.append(And.new(and_condition.tag, condition_list))
  end
end
process(tag, es) click to toggle source
# File lib/fluent/plugin/out_conditional_tag_rewrite.rb, line 64
def process(tag, es)
  multi_event_streams = Hash.new { |hash, key| hash[key] = MultiEventStream.new }

  es.each do |time, record|
    should_rewrite, rewritten_tag = rewrite?(record)
    multi_event_streams[rewritten_tag].add(time, record) if should_rewrite
  end

  # re-emit all event streams / records with rewritten tags
  multi_event_streams.each do |rewritten_tag, event_stream|
    @router.emit_stream(rewritten_tag, event_stream)
  end
end
rewrite?(record) click to toggle source
# File lib/fluent/plugin/out_conditional_tag_rewrite.rb, line 78
def rewrite?(record)
  @and_conditions.each do |and_condition|
    next unless and_condition.match?(record)

    return true, and_condition.tag
  end

  [!@fallback_tag.nil?, @fallback_tag]
end