2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-20 15:50:20 -04:00
|
|
|
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)
|
2018-12-05 15:54:40 -05:00
|
|
|
data[Gitlab::CorrelationId::LOG_KEY] = Gitlab::CorrelationId.current_id
|
2018-07-20 15:50:20 -04:00
|
|
|
|
|
|
|
case message
|
|
|
|
when String
|
|
|
|
data[:message] = message
|
|
|
|
when Hash
|
|
|
|
data.merge!(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
data.to_json + "\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|