Class: Fluent::YohoushiOutput::PlaceholderExpander

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#placeholdersObject (readonly)

Returns the value of attribute placeholders.



182
183
184
# File 'lib/fluent/plugin/out_yohoushi.rb', line 182

def placeholders
  @placeholders
end

Instance Method Details

#expand(str) ⇒ Object



203
204
205
206
207
208
# File 'lib/fluent/plugin/out_yohoushi.rb', line 203

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



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/fluent/plugin/out_yohoushi.rb', line 184

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

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

  @placeholders = placeholders
end