Class: Fluent::Plugin::CriParser

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/parser_cri.rb', line 31

def configure(conf)
  super

  @sub_parser = nil
  if parser_config = conf.elements('parse').first
    type = parser_config['@type']
    @sub_parser = Fluent::Plugin.new_parser(type, parent: self.owner)
    @sub_parser.configure(parser_config)
  end
end

#parse(text) {|time, record| ... } ⇒ Object

Yields:

  • (time, record)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fluent/plugin/parser_cri.rb', line 42

def parse(text)
  elems = text.split(/\s/.freeze, 4)
  return yield nil if elems.size != 4

  if @sub_parser
    time = record = nil
    @sub_parser.parse(elems[3]) { |t, r|
      time = t
      record = r
    }
    if @merge_cri_fields && record
      record['stream'] = elems[1]
      record['logtag'] = elems[2]
    end
  else
    record = {
      "stream" => elems[1],
      "logtag" => elems[2],
      "log" => elems[3]
    }
    t = elems[0]
    time = @time_parser.parse(t)
    if @keep_time_key
      record[@time_key] = t
    end
  end

  yield time, record
end