class Fluent::Plugin::GrokParser

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/parser_grok.rb, line 35
def initialize
  super
  @default_parser = Fluent::Plugin::NoneParser.new
end

Public Instance Methods

configure(conf={}) click to toggle source
Calls superclass method
# File lib/fluent/plugin/parser_grok.rb, line 40
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.exist? @custom_pattern_path
      Dir.glob(@custom_pattern_path + "/*") do |pattern_file_path|
        @grok.add_patterns_from_file(pattern_file_path)
      end
    elsif File.exist? @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 63
def parse(text)
  @grok.parsers.each do |name_or_index, parser|
    parser.parse(text) do |time, record|
      if time and record
        record[@grok_name_key] = name_or_index if @grok_name_key
        yield time, record
        return
      end
    end
  end
  @default_parser.parse(text) do |time, record|
    record[@grok_failure_key] = "No grok pattern matched" if @grok_failure_key
    yield time, record
  end
end