class Fluent::Plugin::CriParser

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# 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) { |nil| ... } click to toggle source
# 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],
      "message" => elems[3]
    }
    t = elems[0]
    time = @time_parser.parse(t)
    if @keep_time_key
      record[@time_key] = t
    end
  end

  yield time, record
end