Class: Fluent::Plugin::MultilineGreenplumLogParser

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

Instance Method Summary collapse

Constructor Details

#initializeMultilineGreenplumLogParser

Returns a new instance of MultilineGreenplumLogParser.



25
26
27
28
# File 'lib/fluent/plugin/parser_multiline_greenplum_log.rb', line 25

def initialize
  super
  require 'csv'
end

Instance Method Details

#configure(conf) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/fluent/plugin/parser_multiline_greenplum_log.rb', line 29

def configure(conf)
  super
  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)


74
75
76
# File 'lib/fluent/plugin/parser_multiline_greenplum_log.rb', line 74

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

#has_firstline?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/fluent/plugin/parser_multiline_greenplum_log.rb', line 71

def has_firstline?
  !!@format_firstline
end

#parse(text) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/fluent/plugin/parser_multiline_greenplum_log.rb', line 63

def parse(text)
  if block_given?
    yield values_map(CSV.parse_line(text))
  else
    return values_map(CSV.parse_line(text))
  end
end

#values_map(values) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fluent/plugin/parser_multiline_greenplum_log.rb', line 37

def values_map(values)
  record = Hash[keys.zip(values.map { |value| convert_value_to_nil(value) })]

  if @time_key
    value = @keep_time_key ? record[@time_key] : record.delete(@time_key)
    time = if value.nil?
             if @estimate_current_event
               Fluent::EventTime.now
             else
               nil
             end
           else
             @mutex.synchronize { @time_parser.parse(value) }
           end
  elsif @estimate_current_event
    time = Fluent::EventTime.now
  else
    time = nil
  end

  convert_field_type!(record) if @type_converters

  return time, record
end