Class: ManageIQ::Loggers::JSONLogger::Formatter
- Inherits:
-
Base::Formatter
- Object
- Logger::Formatter
- Base::Formatter
- ManageIQ::Loggers::JSONLogger::Formatter
- Defined in:
- lib/manageiq/loggers/json_logger.rb
Constant Summary collapse
- SEVERITY_MAP =
{ "DEBUG" => "debug", "INFO" => "info", "WARN" => "warning", "ERROR" => "err", "FATAL" => "crit", "UNKNOWN" => "unknown" # Others that don't match up: alert emerg notice trace }.freeze
Constants inherited from Base::Formatter
Instance Method Summary collapse
- #call(severity, time, progname, msg) ⇒ Object
-
#initialize ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize ⇒ Formatter
Returns a new instance of Formatter.
20 21 22 23 |
# File 'lib/manageiq/loggers/json_logger.rb', line 20 def initialize super require 'json' end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/manageiq/loggers/json_logger.rb', line 25 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" rescue Encoding::UndefinedConversionError raise unless msg.encoding == Encoding::ASCII_8BIT msg.force_encoding("UTF-8") retry end |