Class: Fluent::Plugin::MultilineParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/fluent/plugin/parser_multiline.rb

Direct Known Subclasses

Compat::TextParser::MultilineParser

Constant Summary collapse

FORMAT_MAX_NUM =
20

Constants inherited from Parser

Parser::TimeParser

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes inherited from Parser

#estimate_current_event

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods inherited from Parser

#call, #initialize

Methods included from TimeMixin::Parser

included, #time_parser_create

Methods included from OwnedByMixin

#log, #owner, #owner=

Methods inherited from Base

#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #has_router?, #initialize, #inspect, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, included, #initialize, lookup_type, register_type

Constructor Details

This class inherits a constructor from Fluent::Plugin::Parser

Instance Method Details

#configure(conf) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fluent/plugin/parser_multiline.rb', line 28

def configure(conf)
  super

  formats = parse_formats(conf).compact.map { |f| f[1..-2] }.join
  begin
    regexp = Regexp.new(formats, Regexp::MULTILINE)
    if regexp.named_captures.empty?
      raise "No named captures"
    end
    regexp_conf = Fluent::Config::Element.new("", "", { "expression" => "/#{formats}/", "multiline" => true }, [])
    @parser = Fluent::Plugin::RegexpParser.new
    @parser.configure(conf + regexp_conf)
  rescue => e
    raise Fluent::ConfigError, "Invalid regexp '#{formats}': #{e}"
  end

  if @format_firstline
    check_format_regexp(@format_firstline, 'format_firstline')
    @firstline_regex = Regexp.new(@format_firstline[1..-2])
  end
end

#firstline?(text) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/fluent/plugin/parser_multiline.rb', line 58

def firstline?(text)
  @firstline_regex.match(text)
end

#has_firstline?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/fluent/plugin/parser_multiline.rb', line 54

def has_firstline?
  !!@format_firstline
end

#parse(text, &block) ⇒ Object



50
51
52
# File 'lib/fluent/plugin/parser_multiline.rb', line 50

def parse(text, &block)
  @parser.call(text, &block)
end