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 Method Summary collapse
Instance Method Details
#configure(conf) ⇒ Object
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 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fluent/plugin/out_grep.rb', line 16 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 @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 @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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fluent/plugin/out_grep.rb', line 57 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 |