Class: Fluent::Plugin::StringScrubOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::StringScrubOutput
- Defined in:
- lib/fluent/plugin/out_string_scrub.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ StringScrubOutput
constructor
A new instance of StringScrubOutput.
- #process(tag, es) ⇒ Object
- #recv_record(record) ⇒ Object
- #with_scrub(string) ⇒ Object
Constructor Details
#initialize ⇒ StringScrubOutput
Returns a new instance of StringScrubOutput.
13 14 15 |
# File 'lib/fluent/plugin/out_string_scrub.rb', line 13 def initialize super end |
Instance Method Details
#configure(conf) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fluent/plugin/out_string_scrub.rb', line 17 def configure(conf) super if conf['@label'].nil? 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 end if @replace_char =~ /\\u\{*[A-F0-9]{4}\}*/ @replace_char = eval("\"#{@replace_char}\"") end end |
#process(tag, es) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fluent/plugin/out_string_scrub.rb', line 41 def process(tag, es) 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 es.each do |time,record| scrubbed = recv_record(record) next if scrubbed.nil? router.emit(tag, time, scrubbed) end end |
#recv_record(record) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fluent/plugin/out_string_scrub.rb', line 66 def recv_record(record) scrubbed = {} record.each do |k,v| if v.instance_of? Hash scrubbed[with_scrub(k)] = recv_record(v) elsif v.instance_of? Integer scrubbed[k] = v else scrubbed[with_scrub(k)] = with_scrub(v) end end scrubbed end |
#with_scrub(string) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fluent/plugin/out_string_scrub.rb', line 80 def with_scrub(string) begin string =~ // return string rescue ArgumentError => e raise e unless e..index("invalid byte sequence in") == 0 if string.frozen? string = string.dup.scrub!(@replace_char) else string.scrub!(@replace_char) end retry end end |