debian-mirror-gitlab/lib/gitlab/json_logger.rb
2021-10-27 15:23:28 +05:30

31 lines
672 B
Ruby

# 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 = default_attributes
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
Gitlab::Json.dump(data) + "\n"
end
protected
def default_attributes
{}
end
end
end