Class: Fluent::Plugin::MultilineParser

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

Direct Known Subclasses

Compat::TextParser::MultilineParser

Defined Under Namespace

Classes: MultilineRegexpParser

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?, #initialize, #parse_io, #parse_partial_data, #parse_time, #parse_with_timeout, #parser_type, #start, #stop, #string_like_null

Methods included from TimeMixin::Parser

included, #time_parser_create

Methods included from OwnedByMixin

#log, #owner, #owner=

Methods inherited from Base

#acquire_worker_lock, #after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #called_in_test?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #get_lock_path, #has_router?, #initialize, #inspect, #multi_workers_ready?, #plugin_root_dir, #reloadable_plugin?, #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::Parser

Instance Method Details

#configure(conf) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fluent/plugin/parser_multiline.rb', line 54

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}/m" }, [])
    @parser = Fluent::Plugin::MultilineParser::MultilineRegexpParser.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)


106
107
108
# File 'lib/fluent/plugin/parser_multiline.rb', line 106

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

#has_firstline?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/fluent/plugin/parser_multiline.rb', line 102

def has_firstline?
  !!@format_firstline
end

#parse(text, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fluent/plugin/parser_multiline.rb', line 76

def parse(text, &block)
  loop do
    m =
      if @unmatched_lines
        @parser.call(text) do |time, record|
          if time && record
            yield(time, record)
          else
            yield(Fluent::EventTime.now, { 'unmatched_line' => text })
          end
        end
      else
        @parser.call(text, &block)
      end

    return if m.nil?

    text = m.post_match
    if text.start_with?("\n")
      text = text[1..-1]
    end

    return if text.empty?
  end
end