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) ⇒ Object
-
#initialize(log) ⇒ PlaceholderExpander
constructor
A new instance of PlaceholderExpander.
- #prepare_placeholders(time, record, opts) ⇒ Object
Constructor Details
#initialize(log) ⇒ PlaceholderExpander
Returns a new instance of PlaceholderExpander.
127 128 129 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 127 def initialize(log) @log = log end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
125 126 127 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 125 def log @log end |
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
125 126 127 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 125 def placeholders @placeholders end |
Instance Method Details
#expand(str) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 150 def (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
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 131 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 |