Class: CMDx::LogFormatters::Logstash
- Inherits:
-
Object
- Object
- CMDx::LogFormatters::Logstash
- Defined in:
- lib/cmdx/log_formatters/logstash.rb
Overview
Formats log messages as Logstash-compatible JSON for structured logging
This formatter converts log entries into Logstash-compatible JSON format with standardized fields including @version, @timestamp, severity, program name, process ID, and formatted message. The output follows Logstash event format specifications for seamless integration with ELK stack and similar systems.
Instance Method Summary collapse
-
#call(severity, time, progname, message) ⇒ String
Formats a log entry as a Logstash-compatible JSON string.
Instance Method Details
#call(severity, time, progname, message) ⇒ String
Formats a log entry as a Logstash-compatible JSON string
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cmdx/log_formatters/logstash.rb', line 27 def call(severity, time, progname, ) hash = { severity:, progname:, pid: Process.pid, message: Utils::Format.to_log(), "@version" => "1", "@timestamp" => time.utc.iso8601(6) } ::JSON.dump(hash) << "\n" end |