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)
|
2021-08-04 14:09:57 -04:00
|
|
|
data = default_attributes
|
2018-07-20 15:50:20 -04:00
|
|
|
data[:severity] = severity
|
|
|
|
data[:time] = timestamp.utc.iso8601(3)
|
2019-02-18 15:57:22 -05:00
|
|
|
data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
|
2018-07-20 15:50:20 -04:00
|
|
|
|
|
|
|
case message
|
|
|
|
when String
|
|
|
|
data[:message] = message
|
|
|
|
when Hash
|
|
|
|
data.merge!(message)
|
|
|
|
end
|
|
|
|
|
2020-07-13 11:09:08 -04:00
|
|
|
Gitlab::Json.dump(data) + "\n"
|
2018-07-20 15:50:20 -04:00
|
|
|
end
|
2021-08-04 14:09:57 -04:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def default_attributes
|
|
|
|
{}
|
|
|
|
end
|
2018-07-20 15:50:20 -04:00
|
|
|
end
|
|
|
|
end
|