Class: CMDx::LogFormatters::Logstash

Inherits:
Object
  • Object
show all
Defined in:
lib/cmdx/log_formatters/logstash.rb

Overview

‘Logger` formatter that produces one JSON line per entry in the shape expected by Logstash (`@version` + `@timestamp`).

Instance Method Summary collapse

Instance Method Details

#call(severity, time, progname, message) ⇒ String

Returns JSON line terminated by ‘“n”`.

Parameters:

  • severity (String)

    Logger severity name

  • time (Time)
  • progname (String, nil)
  • message (Object)

Returns:

  • (String)

    JSON line terminated by ‘“n”`



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cmdx/log_formatters/logstash.rb', line 14

def call(severity, time, progname, message)
  hash = {
    severity:,
    progname:,
    pid: Process.pid,
    message: message.respond_to?(:to_h) ? message.to_h : message,
    "@version" => "1",
    "@timestamp" => time.utc.iso8601(6)
  }

  ::JSON.dump(hash) << "\n"
end