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.



127
128
129
# File 'lib/ocular/logging/kafka_logger.rb', line 127

def initialize
    @datetime_format = nil
end

Instance Attribute Details

#datetime_formatObject

Returns the value of attribute datetime_format.



125
126
127
# File 'lib/ocular/logging/kafka_logger.rb', line 125

def datetime_format
  @datetime_format
end

Instance Method Details

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



152
153
154
155
156
157
158
159
160
161
162
# 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) ⇒ Object



142
143
144
145
146
147
148
149
150
# 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) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# 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