Class: Ocular::Logging::KafkaLogger::Formatter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeFormatter

Returns a new instance of Formatter.



132
133
134
# File 'lib/ocular/logging/kafka_logger.rb', line 132

def initialize
    @datetime_format = nil
end

Instance Attribute Details

#datetime_formatObject

Returns the value of attribute datetime_format.



130
131
132
# File 'lib/ocular/logging/kafka_logger.rb', line 130

def datetime_format
  @datetime_format
end

Instance Method Details

#format_cause(type, environment, time, progname) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/ocular/logging/kafka_logger.rb', line 157

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



147
148
149
150
151
152
153
154
155
# File 'lib/ocular/logging/kafka_logger.rb', line 147

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



136
137
138
139
140
141
142
143
144
145
# File 'lib/ocular/logging/kafka_logger.rb', line 136

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