class ManageIQ::Loggers::Container::Formatter

Constants

SEVERITY_MAP

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/manageiq/loggers/container.rb, line 31
def initialize
  super
  require 'json'
end

Public Instance Methods

call(severity, time, progname, msg) click to toggle source
# File lib/manageiq/loggers/container.rb, line 36
def call(severity, time, progname, msg)
  # From https://github.com/ViaQ/elasticsearch-templates/releases -> Downloads -> *.asciidoc
  # NOTE: These values are in a specific order for easier human readbility via STDOUT
  payload = {
    :@timestamp => format_datetime(time),
    :hostname   => hostname,
    :pid        => $PROCESS_ID,
    :tid        => thread_id,
    :service    => progname,
    :level      => translate_error(severity),
    :message    => prefix_task_id(msg2str(msg)),
    :request_id => request_id
    # :tags => "tags string",
  }.compact
  JSON.generate(payload) << "\n"
end

Private Instance Methods

hostname() click to toggle source
# File lib/manageiq/loggers/container.rb, line 55
def hostname
  @hostname ||= ENV["HOSTNAME"]
end
request_id() click to toggle source
# File lib/manageiq/loggers/container.rb, line 67
def request_id
  Thread.current[:request_id] || Thread.current[:current_request]&.request_id.tap do |request_id|
    if request_id
      require "active_support/deprecation"
      ActiveSupport::Deprecation.warn("Usage of `Thread.current[:current_request]&.request_id` will be deprecated in version 0.5.0. Please switch to `Thread.current[:request_id]` to log request_id automatically.")
    end
  end
end
thread_id() click to toggle source
# File lib/manageiq/loggers/container.rb, line 59
def thread_id
  Thread.current.object_id.to_s(16)
end
translate_error(level) click to toggle source
# File lib/manageiq/loggers/container.rb, line 63
def translate_error(level)
  SEVERITY_MAP[level] || "unknown"
end