Class: Fluent::GrepOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::GrepOutput
- Defined in:
- lib/fluent/plugin/out_grep.rb
Constant Summary collapse
- REGEXP_MAX_NUM =
20
Instance Attribute Summary collapse
-
#excludes ⇒ Object
readonly
Returns the value of attribute excludes.
-
#regexps ⇒ Object
readonly
for test.
Instance Method Summary collapse
Instance Attribute Details
#excludes ⇒ Object (readonly)
Returns the value of attribute excludes.
18 19 20 |
# File 'lib/fluent/plugin/out_grep.rb', line 18 def excludes @excludes end |
#regexps ⇒ Object (readonly)
for test
17 18 19 |
# File 'lib/fluent/plugin/out_grep.rb', line 17 def regexps @regexps end |
Instance Method Details
#configure(conf) ⇒ Object
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fluent/plugin/out_grep.rb', line 20 def configure(conf) super @regexps = {} @regexps[@input_key] = Regexp.compile(@regexp) if @input_key and @regexp (1..REGEXP_MAX_NUM).each do |i| next unless conf["regexp#{i}"] key, regexp = conf["regexp#{i}"].split(/ /, 2) raise Fluent::ConfigError, "regexp#{i} does not contain 2 parameters" unless regexp raise Fluent::ConfigError, "regexp#{i} contains a duplicated key, #{key}" if @regexps[key] @regexps[key] = Regexp.compile(regexp) end @excludes = {} @excludes[@input_key] = Regexp.compile(@exclude) if @input_key and @exclude (1..REGEXP_MAX_NUM).each do |i| next unless conf["exclude#{i}"] key, exclude = conf["exclude#{i}"].split(/ /, 2) raise Fluent::ConfigError, "exclude#{i} does not contain 2 parameters" unless exclude raise Fluent::ConfigError, "exclude#{i} contains a duplicated key, #{key}" if @excludes[key] @excludes[key] = Regexp.compile(exclude) end if @tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil? @add_tag_prefix = 'greped' # not ConfigError to support lower version compatibility end @tag_prefix = "#{@add_tag_prefix}." if @add_tag_prefix @tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix @tag_proc = if @tag Proc.new {|tag| @tag } elsif @tag_prefix and @tag_prefix_match Proc.new {|tag| "#{@tag_prefix}#{lstrip(tag, @tag_prefix_match)}" } elsif @tag_prefix_match Proc.new {|tag| lstrip(tag, @tag_prefix_match) } elsif @tag_prefix Proc.new {|tag| "#{@tag_prefix}#{tag}" } else Proc.new {|tag| tag } end end |
#emit(tag, es, chain) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fluent/plugin/out_grep.rb', line 63 def emit(tag, es, chain) emit_tag = @tag_proc.call(tag) es.each do |time,record| catch(:break_loop) do @regexps.each do |key, regexp| throw :break_loop unless match(regexp, record[key].to_s) end @excludes.each do |key, exclude| throw :break_loop if match(exclude, record[key].to_s) end Fluent::Engine.emit(emit_tag, time, record) end end chain.next rescue => e $log.warn e. $log.warn e.backtrace.join(', ') end |