Class: Fluent::RecordModifierOutput

Inherits:
Output
  • Object
show all
Includes:
SetTagKeyMixin
Defined in:
lib/fluent/plugin/out_record_modifier.rb

Constant Summary collapse

BUILTIN_CONFIGURATIONS =
%W(type tag include_tag_key tag_key char_encoding remove_keys whitelist_keys)

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fluent/plugin/out_record_modifier.rb', line 36

def configure(conf)
  super

  @map = {}
  conf.each_pair { |k, v|
    unless BUILTIN_CONFIGURATIONS.include?(k)
      check_config_placeholders(k, v)
      conf.has_key?(k)
      @map[k] = v
    end
  }

  if @char_encoding
    from, to = @char_encoding.split(':', 2)
    @from_enc = Encoding.find(from)
    @to_enc = Encoding.find(to) if to

    m = if @to_enc
          method(:convert_encoding)
        else
          method(:set_encoding)
        end

    (class << self; self; end).module_eval do
      define_method(:change_encoding, m)
    end
  end

  if @remove_keys and @whitelist_keys
    raise Fluent::ConfigError, "remove_keys and whitelist_keys are exclusive with each other."
  elsif @remove_keys
    @remove_keys = @remove_keys.split(',').map(&:strip)
  elsif @whitelist_keys
    @whitelist_keys = @whitelist_keys.split(',').map(&:strip)
  end
end

#emit(tag, es, chain) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/fluent/plugin/out_record_modifier.rb', line 73

def emit(tag, es, chain)
  stream = MultiEventStream.new
  es.each { |time, record|
    filter_record(tag, time, record)
    stream.add(time, modify_record(record))
  }
  Fluent::Engine.emit_stream(@tag, stream)

  chain.next
end