Class: Fluent::EvalFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::EvalFilter
- Defined in:
- lib/fluent/plugin/filter_eval.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #filter_stream(tag, es) ⇒ Object
-
#initialize ⇒ EvalFilter
constructor
A new instance of EvalFilter.
Constructor Details
#initialize ⇒ EvalFilter
7 8 9 |
# File 'lib/fluent/plugin/filter_eval.rb', line 7 def initialize super end |
Instance Method Details
#configure(conf) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fluent/plugin/filter_eval.rb', line 11 def configure(conf) super if @requires @requires.split(',').each do |lib| begin require lib rescue Exception => e raise Fluent::ConfigError, "\n#{e.message}\n#{e.backtrace.join("\n")}" end end end conf.keys.select { |key| key =~ /^config\d+$/ }.sort_by { |key| key.sub('config', '').to_i }.each do |key| begin instance_eval("#{conf[key]}") rescue Exception => e raise Fluent::ConfigError, "#{key} #{conf[key]}\n" + e.to_s end end @filters = [] conf.keys.select { |key| key =~ /^filter\d+$/ }.sort_by { |key| key.sub('filter', '').to_i }.each do |key| begin @filters << instance_eval("lambda do |tag, time, record| #{conf[key]} end") rescue Exception => e raise Fluent::ConfigError, "#{key} #{conf[key]}\n" + e.to_s end end if @filters.empty? raise Fluent::ConfigError, "missing filters" end end |
#filter_stream(tag, es) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fluent/plugin/filter_eval.rb', line 46 def filter_stream(tag, es) new_es = MultiEventStream.new es.each { |time, record| begin filtered_record = filter_record(tag, time, record) new_es.add(*filtered_record) if filtered_record rescue => e router.emit_error_event(tag, time, record, e) end } new_es end |