Class: Fluent::RecordReformerOutput::PlaceholderExpander
- Inherits:
-
Object
- Object
- Fluent::RecordReformerOutput::PlaceholderExpander
- Defined in:
- lib/fluent/plugin/out_record_reformer.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#placeholders ⇒ Object
readonly
Returns the value of attribute placeholders.
Instance Method Summary collapse
- #expand(str, force_stringify = false) ⇒ Object
-
#initialize(params) ⇒ PlaceholderExpander
constructor
A new instance of PlaceholderExpander.
- #prepare_placeholders(time, record, opts) ⇒ Object
Constructor Details
#initialize(params) ⇒ PlaceholderExpander
Returns a new instance of PlaceholderExpander.
188 189 190 191 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 188 def initialize(params) @log = params[:log] @auto_typecast = params[:auto_typecast] end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
186 187 188 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 186 def log @log end |
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
186 187 188 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 186 def placeholders @placeholders end |
Instance Method Details
#expand(str, force_stringify = false) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 212 def (str, force_stringify=false) if @auto_typecast and !force_stringify single_placeholder_matched = str.match(/\A(\${[^}]+}|__[A-Z_]+__)\z/) if single_placeholder_matched log_unknown_placeholder($1) return @placeholders[single_placeholder_matched[1]] end end str.gsub(/(\${[^}]+}|__[A-Z_]+__)/) { log_unknown_placeholder($1) @placeholders[$1] } end |
#prepare_placeholders(time, record, opts) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 193 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 |