Class: Fluent::TailMultilineInput::MultilineTextParser

Inherits:
TextParser
  • Object
show all
Defined in:
lib/fluent/plugin/in_tail_multiline.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf, required = true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/in_tail_multiline.rb', line 6

def configure(conf, required=true)
  format = conf['format']
  if format == nil
    raise ConfigError, "'format' parameter is required"
  elsif format[0] != ?/ || format[format.length-1] != ?/ 
    raise ConfigError, "'format' should be RegEx. Template is not supported in multiline mode"
  end
  
  begin
    @regex = Regexp.new(format[1..-2],Regexp::MULTILINE)
    if @regex.named_captures.empty?
      raise "No named captures"
    end
  rescue
    raise ConfigError, "Invalid regexp in format '#{format[1..-2]}': #{$!}"
  end

  @parser = RegexpParser.new(@regex)

  if @parser.respond_to?(:configure)
    @parser.configure(conf)
  end

  format_firstline = conf['format_firstline']
  if format_firstline
    # Use custom matcher for 1st line
    if format_firstline[0] == '/' && format_firstline[format_firstline.length-1] == '/'
      @regex = Regexp.new(format_firstline[1..-2])
    else
      raise ConfigError, "Invalid regexp in format_firstline '#{format_firstline[1..-2]}': #{$!}"
    end
  end

  return true
end

#match_firstline(text) ⇒ Object



42
43
44
# File 'lib/fluent/plugin/in_tail_multiline.rb', line 42

def match_firstline(text)
  @regex.match(text)
end