Class: Fluent::Plugin::IgnoreFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_ignore.rb

Constant Summary collapse

REGEXP_MAX_NUM =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#excludesObject (readonly)

Returns the value of attribute excludes.



14
15
16
# File 'lib/fluent/plugin/filter_ignore.rb', line 14

def excludes
  @excludes
end

#regexpsObject (readonly)

for test



13
14
15
# File 'lib/fluent/plugin/filter_ignore.rb', line 13

def regexps
  @regexps
end

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
# File 'lib/fluent/plugin/filter_ignore.rb', line 16

def configure(conf)
  super

  @regexps = []
  (1..REGEXP_MAX_NUM).each do |i|
    next unless conf["regexp#{i}"]
    key, regexp = conf["regexp#{i}"].split(/ /, 2)
    raise ConfigError, "regexp#{i} does not contain 2 parameters" unless regexp
    @regexps.push({key: key, regexp: Regexp.compile(regexp)})
  end

  @excludes = []
  (1..REGEXP_MAX_NUM).each do |i|
    next unless conf["exclude#{i}"]
    key, regexp = conf["exclude#{i}"].split(/ /, 2)
    raise ConfigError, "exclude#{i} does not contain 2 parameters" unless regexp
    @excludes.push({key: key, regexp: Regexp.compile(regexp)})
  end
end

#filter(tag, time, record) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fluent/plugin/filter_ignore.rb', line 36

def filter(tag, time, record)
  result = record
  begin
    catch(:break_loop) do
      @regexps.each do |o|
        throw :break_loop unless match(o[:regexp], record[o[:key]].to_s)
      end
      @excludes.each do |o|
        throw :break_loop if match(o[:regexp], record[o[:key]].to_s)
      end
      result = nil
    end
  rescue => e
    log.warn "failed to grep events", :error_class => e.class, :error => e.message
    log.warn_backtrace
  end
  result
end