Class: Fluent::RecordReformerOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_record_reformer.rb

Defined Under Namespace

Classes: PlaceholderExpander, RubyPlaceholderExpander

Constant Summary collapse

BUILTIN_CONFIGURATIONS =
%W(type output_tag remove_keys renew_record enable_ruby)

Instance Method Summary collapse

Constructor Details

#initializeRecordReformerOutput

Returns a new instance of RecordReformerOutput.



7
8
9
# File 'lib/fluent/plugin/out_record_reformer.rb', line 7

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fluent/plugin/out_record_reformer.rb', line 18

def configure(conf)
  super

  @map = {}
  conf.each_pair { |k, v|
    next if BUILTIN_CONFIGURATIONS.include?(k)
    conf.has_key?(k) # to suppress unread configuration warning
    @map[k] = v
  }
  # <record></record> directive
  conf.elements.select { |element| element.name == 'record' }.each { |element|
    element.each_pair { |k, v|
      element.has_key?(k) # to suppress unread configuration warning
      @map[k] = v
    }
  }

  if @remove_keys
    @remove_keys = @remove_keys.split(',')
  end

  @placeholder_expander =
    if @enable_ruby
      # require utilities which would be used in ruby placeholders
      require 'pathname'
      require 'uri'
      require 'cgi'
      RubyPlaceholderExpander.new
    else
      PlaceholderExpander.new
    end

  @hostname = Socket.gethostname
end

#emit(tag, es, chain) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fluent/plugin/out_record_reformer.rb', line 53

def emit(tag, es, chain)
  tag_parts = tag.split('.')
  tag_prefix = tag_prefix(tag_parts)
  tag_suffix = tag_suffix(tag_parts)
  placeholders = {
    'tag' => tag,
    'tags' => tag_parts,
    'tag_parts' => tag_parts,
    'tag_prefix' => tag_prefix,
    'tag_suffix' => tag_suffix,
    'hostname' => @hostname,
  }
  es.each { |time, record|
    new_tag, new_record = reform(@output_tag, time, record, placeholders)
    Engine.emit(new_tag, time, new_record)
  }
  chain.next
rescue => e
  $log.warn "record_reformer: #{e.class} #{e.message} #{e.backtrace.first}"
end