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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2023-01-13 00:05:48 +05:30
require 'labkit/logging'
2018-12-13 13:39:08 +05:30
2018-11-18 11:00:15 +05:30
module Gitlab
2023-01-13 00:05:48 +05:30
class JsonLogger < ::Labkit::Logging::JsonLogger
class << self
def file_name_noext
raise NotImplementedError, "JsonLogger implementations must provide file_name_noext implementation"
end
def file_name
file_name_noext + ".log"
end
def debug(message)
build.debug(message)
end
def error(message)
build.error(message)
end
def warn(message)
build.warn(message)
end
2018-11-18 11:00:15 +05:30
2023-01-13 00:05:48 +05:30
def info(message)
build.info(message)
end
2018-11-18 11:00:15 +05:30
2023-01-13 00:05:48 +05:30
def build
Gitlab::SafeRequestStore[cache_key] ||=
new(full_log_path, level: log_level)
2018-11-18 11:00:15 +05:30
end
2023-01-13 00:05:48 +05:30
def cache_key
"logger:" + full_log_path.to_s
end
def full_log_path
Rails.root.join("log", file_name)
end
2018-11-18 11:00:15 +05:30
end
2021-10-27 15:23:28 +05:30
2023-01-13 00:05:48 +05:30
private
2021-10-27 15:23:28 +05:30
2023-01-13 00:05:48 +05:30
# Override Labkit's default impl, which uses the default Ruby platform json module.
def dump_json(data)
Gitlab::Json.dump(data)
2021-10-27 15:23:28 +05:30
end
2018-11-18 11:00:15 +05:30
end
end