gitlab-org--gitlab-foss/lib/gitlab/json_logger.rb
Stan Hu 477f9ed78f Bring JsonLogger to CE
This backports a module that was in EE for Geo so that other modules
can have structured logging support.
2018-07-20 12:50:20 -07:00

22 lines
450 B
Ruby

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)
case message
when String
data[:message] = message
when Hash
data.merge!(message)
end
data.to_json + "\n"
end
end
end