summaryrefslogtreecommitdiff
path: root/lib/gitlab/sidekiq_logging/json_formatter.rb
blob: 98f8222fd035c2f2e84dfe3e2f4ca538521d407e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Gitlab
  module SidekiqLogging
    class JSONFormatter
      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)
        end

        output.to_json + "\n"
      end
    end
  end
end