2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
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)
|
2019-07-31 22:56:46 +05:30
|
|
|
data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
case message
|
|
|
|
when String
|
|
|
|
data[:message] = message
|
|
|
|
when Hash
|
|
|
|
data.merge!(message)
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
Gitlab::Json.dump(data) + "\n"
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|