4f4de36cac
This change is a fairly straightforward refactor to extract the tracing and correlation-id code from the gitlab rails codebase into the new LabKit-Ruby project. The corresponding import into LabKit-Ruby was in https://gitlab.com/gitlab-org/labkit-ruby/merge_requests/1 The code itself remains very similar for now. Extracting it allows us to reuse it in other projects, such as Gitaly-Ruby. This will give us the advantages of correlation-ids and distributed tracing in that project too.
25 lines
585 B
Ruby
25 lines
585 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 = {}
|
|
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
|
|
|
|
data.to_json + "\n"
|
|
end
|
|
end
|
|
end
|