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.
20 21 22 |
# File 'lib/fluent/plugin/out_grep.rb', line 20 def excludes @excludes end |
#regexps ⇒ Object (readonly)
for test
19 20 21 |
# File 'lib/fluent/plugin/out_grep.rb', line 19 def regexps @regexps end |
Instance Method Details
#configure(conf) ⇒ Object
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 |
# File 'lib/fluent/plugin/out_grep.rb', line 27 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? and @add_tag_suffix.nil? and @remove_tag_suffix.nil? @add_tag_prefix = 'greped' # not ConfigError to support lower version compatibility end @tag_proc = tag_proc end |
#emit(tag, es, chain) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fluent/plugin/out_grep.rb', line 56 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 |