Class: Ocular::Logging::KafkaLogger::Formatter
- Inherits:
-
Object
- Object
- Ocular::Logging::KafkaLogger::Formatter
- Defined in:
- lib/ocular/logging/kafka_logger.rb
Overview
Default formatter for log messages.
Constant Summary collapse
- Format =
"%s, [%s#%d] %5s -- %s: %s\n".freeze
Instance Attribute Summary collapse
-
#datetime_format ⇒ Object
Returns the value of attribute datetime_format.
Instance Method Summary collapse
- #format_cause(type, environment, time, progname) ⇒ Object
- #format_event(property, value, time, progname) ⇒ Object
- #format_message(severity, time, progname, msg) ⇒ Object
-
#initialize ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize ⇒ Formatter
Returns a new instance of Formatter.
84 85 86 |
# File 'lib/ocular/logging/kafka_logger.rb', line 84 def initialize @datetime_format = nil end |
Instance Attribute Details
#datetime_format ⇒ Object
Returns the value of attribute datetime_format.
82 83 84 |
# File 'lib/ocular/logging/kafka_logger.rb', line 82 def datetime_format @datetime_format end |
Instance Method Details
#format_cause(type, environment, time, progname) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ocular/logging/kafka_logger.rb', line 109 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) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/ocular/logging/kafka_logger.rb', line 99 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) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ocular/logging/kafka_logger.rb', line 88 def (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 |