Class: Fluent::Plugin::ForceEncodingFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_force_encoding.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/fluent/plugin/filter_force_encoding.rb', line 32

def configure(conf)
  super

  @accessors = @elements.map do |element|
    [record_accessor_create(element.key), element.encoding]
  end
end

#filter(tag, time, record) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/fluent/plugin/filter_force_encoding.rb', line 40

def filter(tag, time, record)
  @accessors.each do |accessor, encoding|
    raw_value = accessor.call(record)
    value = raw_value&.force_encoding(encoding) || raw_value
    accessor.set(record, value)
  end
  record
end