Class: Fluent::DeparserOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::DeparserOutput
- Defined in:
- lib/fluent/plugin/out_deparser.rb
Instance Method Summary collapse
Instance Method Details
#april_fool_emit(tag, es, chain) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/fluent/plugin/out_deparser.rb', line 12 def april_fool_emit(tag, es, chain) es.each {|time,record| keys = record.keys.shuffle new_record = {@key_name => keys.map{|k| record[k]}.join(' ')} router.emit(@tag, time, new_record) } chain.next end |
#configure(conf) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fluent/plugin/out_deparser.rb', line 26 def configure(conf) if conf['tag'] == 'april.fool' conf['format'] = '%s' conf['format_key_names'] = 'x' end super if @tag == 'april.fool' m = method(:april_fool_emit) (class << self; self; end).module_eval do define_method(:emit, m) end return end if not @tag and not @remove_prefix and not @add_prefix raise Fluent::ConfigError, "missing both of remove_prefix and add_prefix" end if @tag and (@remove_prefix or @add_prefix) raise Fluent::ConfigError, "both of tag and remove_prefix/add_prefix must not be specified" end if @remove_prefix @removed_prefix_string = @remove_prefix + '.' @removed_length = @removed_prefix_string.length end if @add_prefix @added_prefix_string = @add_prefix + '.' end @format_key_names = @format_key_names.split(',') begin dummy = @format % (["x"] * @format_key_names.length) rescue ArgumentError raise Fluent::ConfigError, "mismatch between placeholder of format and format_key_names" end end |
#emit(tag, es, chain) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fluent/plugin/out_deparser.rb', line 64 def emit(tag, es, chain) tag = if @tag @tag else if @remove_prefix and ( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix) tag = tag[@removed_length..-1] end if @add_prefix tag = if tag and tag.length > 0 @added_prefix_string + tag else @add_prefix end end tag end if @reserve_data es.each {|time,record| record.update({@key_name => (@format % @format_key_names.map{|k| record[k]})}) router.emit(tag, time, record) } else es.each {|time,record| new_record = {@key_name => (@format % @format_key_names.map{|k| record[k]})} router.emit(tag, time, new_record) } end chain.next end |