class Fluent::ReplaceOutput

Public Instance Methods

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

  @rules = YAML.load_file(@rules_yaml) rescue nil
  raise Fluent::ConfigError, "#{@rules_yaml} is not found" unless @rules
end
emit(tag, es, chain) click to toggle source
# File lib/fluent/plugin/out_replace.rb, line 16
def emit(tag, es, chain)
  tag = @tag if @tag

  es.each do |time, record|
    begin
      @rules.each do |key, rule|
        target = record[key].to_s

        rule.each do |from, to|
          if match_data = from.to_s.match(/\/(?<pattern>.+)\//)
            pattern = Regexp.new(match_data[:pattern])
            record[key] = target.gsub(pattern, to) if target.match(pattern)
          else
            record[key] = to if from.to_s == target
          end
        end
      end
    rescue
      raise Fluent::ConfigError, 'Invalid YAML format'
    end
    Fluent::Engine.emit(tag, time, record)
  end

  chain.next
end