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::AVAILABLE_PARSER_VALUE_TYPES, Parser::PARSER_TYPES, Parser::TRUTHY_VALUES

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes inherited from Parser

#type_converters

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods inherited from Parser

#build_type_converters, #call, #convert_values, #implement?, #parse_io, #parse_partial_data, #parse_time, #parser_type, #string_like_null

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?, #context_router, #context_router=, #fluentd_worker_id, #has_router?, #initialize, #inspect, #multi_workers_ready?, #plugin_root_dir, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, #initialize, lookup_type, register_type

Constructor Details

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

Instance Method Details

#configure(conf) ⇒ Object



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

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)


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

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

#has_firstline?Boolean

Returns:

  • (Boolean)


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

def has_firstline?
  !!@format_firstline
end

#parse(text, &block) ⇒ Object



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

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