class Fluent::RecordReformerOutputCore::RubyPlaceholderExpander
THIS CLASS MUST BE THREAD-SAFE
Attributes
log[R]
Public Class Methods
new(params)
click to toggle source
# File lib/fluent/plugin/out_record_reformer/core.rb, line 259 def initialize(params) @log = params[:log] @auto_typecast = params[:auto_typecast] @cleanroom_expander = CleanroomExpander.new end
Public Instance Methods
expand(str, placeholders, force_stringify = false)
click to toggle source
Expand string with placeholders
@param [String] str
# File lib/fluent/plugin/out_record_reformer/core.rb, line 308 def expand(str, placeholders, force_stringify = false) @cleanroom_expander.expand( str, placeholders['tag'], placeholders['time'], placeholders['record'], placeholders['tag_parts'], placeholders['tag_prefix'], placeholders['tag_suffix'], placeholders['hostname'], ) rescue => e log.warn "record_reformer: failed to expand `#{str}`", :error_class => e.class, :error => e.message log.warn_backtrace nil end
prepare_placeholders(placeholder_values)
click to toggle source
# File lib/fluent/plugin/out_record_reformer/core.rb, line 301 def prepare_placeholders(placeholder_values) placeholder_values end
preprocess_map(value, force_stringify = false)
click to toggle source
Preprocess record map to convert into ruby string expansion
@param [Hash|String|Array] value record map config @param [Boolean] force_stringify the value must be string, used for hash key
# File lib/fluent/plugin/out_record_reformer/core.rb, line 273 def preprocess_map(value, force_stringify = false) new_value = nil if value.is_a?(String) if @auto_typecast and !force_stringify num_placeholders = value.scan('${').size if num_placeholders == 1 and value.start_with?('${') && value.end_with?('}') new_value = value[2..-2] # ${..} => .. end end unless new_value new_value = "%Q[#{value.gsub('${', '#{')}]" # xx${..}xx => %Q[xx#{..}xx] end elsif value.is_a?(Hash) new_value = {} value.each_pair do |k, v| new_value[preprocess_map(k, true)] = preprocess_map(v) end elsif value.is_a?(Array) new_value = [] value.each_with_index do |v, i| new_value[i] = preprocess_map(v) end else new_value = value end new_value end
time_value(time)
click to toggle source
# File lib/fluent/plugin/out_record_reformer/core.rb, line 265 def time_value(time) Time.at(time) end