class Sidekiq::Logging::LogstashFormatter

Class that takes a log payload and format it to be Logstash-compatible.

Public Instance Methods

call(severity, _time, _progname, data) click to toggle source
# File lib/sidekiq/logging/logstash_formatter.rb, line 9
def call(severity, _time, _progname, data)
  json_data = { severity: severity }

  if data.is_a? Hash
    json_data.merge!(data)
  else
    json_data[:message] = data
  end

  # Merge custom_options to provide customization
  begin
    custom_options&.call(json_data)
  rescue StandardError
    nil
  end
  event = LogStash::Event.new(json_data)

  "#{event.to_json}\n"
end

Private Instance Methods

custom_options() click to toggle source
# File lib/sidekiq/logging/logstash_formatter.rb, line 31
def custom_options
  Sidekiq::Logstash.configuration.custom_options
end