class Fluent::TextParser::GrokParser

Public Class Methods

desc(description) click to toggle source
# File lib/fluent/plugin/parser_grok.rb, line 13
def desc(description)
end
new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/parser_grok.rb, line 25
def initialize
  super
  @default_parser = NoneParser.new
end

Public Instance Methods

configure(conf={}) click to toggle source
Calls superclass method
# File lib/fluent/plugin/parser_grok.rb, line 30
def configure(conf={})
  super

  @grok = Grok.new(self, conf)

  default_pattern_dir = File.expand_path('../../../../patterns/*', __FILE__)
  Dir.glob(default_pattern_dir) do |pattern_file_path|
    @grok.add_patterns_from_file(pattern_file_path)
  end

  if @custom_pattern_path
    if Dir.exists? @custom_pattern_path
      Dir.glob(@custom_pattern_path + '/*') do |pattern_file_path|
        @grok.add_patterns_from_file(pattern_file_path)
      end
    elsif File.exists? @custom_pattern_path
      @grok.add_patterns_from_file(@custom_pattern_path)
    end
  end

  @grok.setup
end
parse(text) { |time, record| ... } click to toggle source
# File lib/fluent/plugin/parser_grok.rb, line 53
def parse(text, &block)
  if block_given?
    @grok.parsers.each do |parser|
      parser.parse(text) do |time, record|
        if time and record
          yield time, record
          return
        end
      end
    end
    yield @default_parser.parse(text)
  else
    @grok.parsers.each do |parser|
      parser.parse(text) do |time, record|
        if time and record
          return time, record
        end
      end
    end
    return @default_parser.parse(text)
  end
end