summaryrefslogtreecommitdiff
path: root/lib/gitlab/json_logger.rb
blob: ab34fb0315850f539724e50d6696bcd69d29891e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module Gitlab
  class JsonLogger < ::Gitlab::Logger
    def self.file_name_noext
      raise NotImplementedError
    end

    def format_message(severity, timestamp, progname, message)
      data = {}
      data[:severity] = severity
      data[:time] = timestamp.utc.iso8601(3)
      data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id

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

      data.to_json + "\n"
    end
  end
end