Class: Fluent::RecordReformerOutput::PlaceholderExpander

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#placeholdersObject (readonly)

Returns the value of attribute placeholders.



107
108
109
# File 'lib/fluent/plugin/out_record_reformer.rb', line 107

def placeholders
  @placeholders
end

Instance Method Details

#expand(str) ⇒ Object



128
129
130
131
132
133
# File 'lib/fluent/plugin/out_record_reformer.rb', line 128

def expand(str)
  str.gsub(/(\${[a-z_]+(\[-?[0-9]+\])?}|__[A-Z_]+__)/) {
    $log.warn "record_reformer: unknown placeholder `#{$1}` found" unless @placeholders.include?($1)
    @placeholders[$1]
  }
end

#prepare_placeholders(time, record, opts) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fluent/plugin/out_record_reformer.rb', line 109

def prepare_placeholders(time, record, opts)
  placeholders = { '${time}' => Time.at(time).to_s }
  record.each {|key, val| placeholders.store("${#{key}}", val) }

  opts.each do |key, val|
    if val.kind_of?(Array)
      size = val.size
      val.each_with_index { |t, idx|
        placeholders.store("${#{key}[#{idx}]}", t)
        placeholders.store("${#{key}[#{idx-size}]}", t) # support [-1]
      }
    else # string, interger, float, and others?
      placeholders["${#{key}}"] = val
    end
  end

  @placeholders = placeholders
end