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.



58
59
60
# File 'lib/ocular/logging/kafka_logger.rb', line 58

def initialize
    @datetime_format = nil
end

Instance Attribute Details

#datetime_formatObject

Returns the value of attribute datetime_format.



56
57
58
# File 'lib/ocular/logging/kafka_logger.rb', line 56

def datetime_format
  @datetime_format
end

Instance Method Details

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



81
82
83
84
85
86
87
88
89
90
# File 'lib/ocular/logging/kafka_logger.rb', line 81

def format_cause(type, environment, time, progname)
    data = {
        "ts" => format_datetime(time),
        "run_id" => progname,
        "triggered_by" => type,
        "environment" => environment
    }

    return data.to_json
end

#format_event(property, value, time, progname) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/ocular/logging/kafka_logger.rb', line 72

def format_event(property, value, time, progname)
    data = {
        "ts" => format_datetime(time),
        "run_id" => progname,
    }
    data[property] = value
    return data.to_json
end

#format_message(severity, time, progname, msg) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/ocular/logging/kafka_logger.rb', line 62

def format_message(severity, time, progname, msg)
    data = {
        "level" => Ocular::Logging::Severity::LABELS[severity],
        "ts" => format_datetime(time),
        "run_id" => progname,
        "msg" => msg2str(msg)
    } 
    return data.to_json
end