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.
112 113 114 |
# File 'lib/ocular/logging/kafka_logger.rb', line 112 def initialize @datetime_format = nil end |
Instance Attribute Details
#datetime_format ⇒ Object
Returns the value of attribute datetime_format.
110 111 112 |
# File 'lib/ocular/logging/kafka_logger.rb', line 110 def datetime_format @datetime_format end |
Instance Method Details
#format_cause(type, environment, time, progname) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ocular/logging/kafka_logger.rb', line 137 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
127 128 129 130 131 132 133 134 135 |
# File 'lib/ocular/logging/kafka_logger.rb', line 127 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
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ocular/logging/kafka_logger.rb', line 116 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 |