Class: Logist::Formatter::Json

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/logist/formatter/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#flat_jsonObject

Returns the value of attribute flat_json.



8
9
10
# File 'lib/logist/formatter/json.rb', line 8

def flat_json
  @flat_json
end

Instance Method Details

#call(severity, timestamp, progname, raw_msg) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/logist/formatter/json.rb', line 10

def call(severity, timestamp, progname, raw_msg)
  msg = normalize_message(raw_msg)
  payload = { level: severity, timestamp: format_datetime(timestamp), environment: ::Rails.env }

  if flat_json && msg.is_a?(Hash)
    payload.merge!(msg)
  else
    payload.merge!(message: msg)
  end

  payload.to_json << "\n"
end