Class: Gitlab::SidekiqLogging::JSONFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/sidekiq_logging/json_formatter.rb

Constant Summary collapse

TIMESTAMP_FIELDS =
%w[created_at enqueued_at started_at retried_at failed_at completed_at].freeze

Instance Method Summary collapse

Instance Method Details

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


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/sidekiq_logging/json_formatter.rb', line 11

def call(severity, timestamp, progname, data)
  output = {
    severity: severity,
    time: timestamp.utc.iso8601(3)
  }

  case data
  when String
    output[:message] = data
  when Hash
    output.merge!(data)

    # jobstr is redundant and can include information we wanted to
    # exclude (like arguments)
    output.delete(:jobstr)

    convert_to_iso8601!(output)
    convert_retry_to_integer!(output)
    process_args!(output)
  end

  output.to_json + "\n"
end