class Fluent::Plugin::DockergelfFilter

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_dockergelf.rb, line 9
def configure(conf)
  super
end
filter_with_time(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_dockergelf.rb, line 13
def filter_with_time(tag, time, record)
  record["logtime"] = Time.at(time.to_f).iso8601(3).to_s
  content = record["log"].strip
  rettime = time
  if (content =~ /^[{](.*)[}]$/)
    content_hash = JSON.parse(content)
    if content_hash["version"].to_s == "1.1" && content_hash["short_message"] != nil #check if gelf format
      content_hash.delete("version")
      msg = content_hash["short_message"]
      content_hash.delete("short_message")
      if content_hash.has_key?("full_message")
        msg = msg + ":" + content_hash["full_message"]
        content_hash.delete("full_message")
      end
      if content_hash.has_key?("timestamp")
        rettime = Fluent::EventTime.from_time(Time.at(content_hash["timestamp"]))
        content_hash.delete("timestamp")
      end
      content_hash.each do |key, value|
        prefix = key[0]
        if prefix == "_"
          record[key[1..-1]] = value
        else
          record[key] = value
        end
      end
      record["log"] = msg
    end
  end
rescue
ensure
  # puts "returning "+ (Time.at(rettime.to_f).iso8601(3).to_s )+" "+record.to_s
  return rettime, record
end