Class: Sidekiq::Logging::LogstashFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/logging/logstash_formatter.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#call(severity, _time, _progname, data) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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