class Ocular::Logging::KafkaLogger::Formatter
Default formatter for log messages.
Constants
- Format
Attributes
datetime_format[RW]
Public Class Methods
new()
click to toggle source
# File lib/ocular/logging/kafka_logger.rb, line 127 def initialize @datetime_format = nil end
Public Instance Methods
format_cause(type, environment, time, progname)
click to toggle source
# File lib/ocular/logging/kafka_logger.rb, line 152 def format_cause(type, environment, time, progname) data = { "@timestamp" => format_datetime(time), "run_id" => progname, "triggered_by" => type, "environment" => environment, "host" => hostname } return data.to_json end
format_event(property, value, time, progname)
click to toggle source
# File lib/ocular/logging/kafka_logger.rb, line 142 def format_event(property, value, time, progname) data = { "@timestamp" => format_datetime(time), "run_id" => progname, "host" => hostname } data[property] = value return data.to_json end
format_message(severity, time, progname, msg)
click to toggle source
# File lib/ocular/logging/kafka_logger.rb, line 131 def format_message(severity, time, progname, msg) data = { "level" => Ocular::Logging::Severity::LABELS[severity], "@timestamp" => format_datetime(time), "run_id" => progname, "msg" => msg2str(msg), "host" => hostname } return data.to_json end
Private Instance Methods
format_datetime(time)
click to toggle source
# File lib/ocular/logging/kafka_logger.rb, line 166 def format_datetime(time) time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ".freeze) end
hostname()
click to toggle source
# File lib/ocular/logging/kafka_logger.rb, line 182 def hostname if !@hostname @hostname = Socket.gethostname end return @hostname end
msg2str(msg)
click to toggle source
# File lib/ocular/logging/kafka_logger.rb, line 170 def msg2str(msg) case msg when ::String msg when ::Exception "#{ msg.message } (#{ msg.class })\n" << (msg.backtrace || []).join("\n") else msg.inspect end end