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 tag output_tag remove_keys renew_record enable_ruby)

Instance Method Summary collapse

Constructor Details

#initializeRecordReformerOutput

Returns a new instance of RecordReformerOutput.



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

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fluent/plugin/out_record_reformer.rb', line 25

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

  if @output_tag and @tag.nil? # for lower version compatibility
    log.warn "out_record_reformer: `output_tag` is deprecated. Use `tag` option instead."
    @tag = @output_tag
  end
  if @tag.nil?
    raise Fluent::ConfigError, "out_record_reformer: `tag` must be specified"
  end

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

  @hostname = Socket.gethostname
end

#emit(tag, es, chain) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fluent/plugin/out_record_reformer.rb', line 68

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,
  }
  last_record = nil
  es.each {|time, record|
    last_record = record # for debug log
    new_tag, new_record = reform(@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}"
  log.debug "record_reformer: tag:#{@tag} map:#{@map} record:#{last_record} placeholders:#{placeholders}"
end