Module: Fluent::GelfPluginUtil

Included in:
Plugin::GelfOutput, TextFormatter::GelfFormatter
Defined in:
lib/fluent/plugin/gelf_plugin_util.rb

Constant Summary collapse

LEVEL_MAP =
{
  '0' => GELF::UNKNOWN, '1' => GELF::UNKNOWN, 'a' => GELF::UNKNOWN,
  '2' => GELF::FATAL, 'c' => GELF::FATAL,
  '3' => GELF::ERROR,
  '4' => GELF::WARN, 'w' => GELF::WARN,
  '5' => GELF::INFO, 'n' => GELF::INFO,
  '6' => GELF::INFO, 'i' => GELF::INFO,
  '7' => GELF::DEBUG, 'd' => GELF::DEBUG,
  'e' => GELF::ERROR
}.freeze

Instance Method Summary collapse

Instance Method Details

#get_internal_json_out(record, key) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/fluent/plugin/gelf_plugin_util.rb', line 19

def get_internal_json_out(record, key)
  json_data = parse_json_field(record[key])
  return record unless json_data

  record.delete(key)
  merge_record_with_json(record, json_data)
rescue Oj::ParseError, EncodingError
  # Return original record if JSON parsing fails
  record
end

#make_gelfentry(tag, time, record, conf = {}) ⇒ Object



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

def make_gelfentry(tag, time, record, conf = {})
  record = get_internal_json_out(record, "message")
  record = get_internal_json_out(record, "log")
  gelfentry = {"_fluentd_tag" => tag, "timestamp" => calculate_timestamp(time)}

  record.each do |k, v|
    process_record_entry(k, v, conf, gelfentry)
  end

  ensure_short_message(gelfentry)
  gelfentry.compact
end