class Fluent::Plugin::GrepFilter
Constants
- REGEXP_MAX_NUM
Attributes
excludes[R]
regexps[R]
for test
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
Fluent::PluginLoggerMixin#configure
# File lib/fluent/plugin/filter_grep.rb, line 34 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 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 = {} (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 end
filter(tag, time, record)
click to toggle source
# File lib/fluent/plugin/filter_grep.rb, line 56 def filter(tag, time, record) result = nil begin catch(:break_loop) do @regexps.each do |key, regexp| throw :break_loop unless ::Fluent::StringUtil.match_regexp(regexp, record[key].to_s) end @excludes.each do |key, exclude| throw :break_loop if ::Fluent::StringUtil.match_regexp(exclude, record[key].to_s) end result = record end rescue => e log.warn "failed to grep events", error: e log.warn_backtrace end result end