Class: CMDx::LogFormatters::JSON
- Inherits:
-
Object
- Object
- CMDx::LogFormatters::JSON
- Defined in:
- lib/cmdx/log_formatters/json.rb
Overview
‘Logger` formatter that emits one JSON object per line with `severity`, ISO8601 `timestamp`, `progname`, `pid`, and `message` (rendered via `#to_h` when available — Result instances serialize themselves).
Instance Method Summary collapse
-
#call(severity, time, progname, message) ⇒ String
JSON line terminated by ‘“n”`.
Instance Method Details
#call(severity, time, progname, message) ⇒ String
Returns JSON line terminated by ‘“n”`.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cmdx/log_formatters/json.rb', line 15 def call(severity, time, progname, ) hash = { severity:, timestamp: time.utc.iso8601(6), progname:, pid: Process.pid, message: .respond_to?(:to_h) ? .to_h : } ::JSON.dump(hash) << "\n" end |