debian-mirror-gitlab/lib/gitlab/json_logger.rb

32 lines
672 B
Ruby
Raw Normal View History

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)
2021-10-27 15:23:28 +05:30
data = default_attributes
2018-11-18 11:00:15 +05:30
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
2021-10-27 15:23:28 +05:30
protected
def default_attributes
{}
end
2018-11-18 11:00:15 +05:30
end
end