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

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

52 lines
990 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module Gitlab
class Logger < ::Logger
2015-04-26 12:48:37 +05:30
def self.file_name
file_name_noext + '.log'
end
2018-11-18 11:00:15 +05:30
def self.debug(message)
build.debug(message)
end
2014-09-02 18:07:02 +05:30
def self.error(message)
build.error(message)
end
2018-11-18 11:00:15 +05:30
def self.warn(message)
build.warn(message)
end
2014-09-02 18:07:02 +05:30
def self.info(message)
build.info(message)
end
def self.read_latest
2018-03-17 18:26:18 +05:30
path = self.full_log_path
return [] unless File.readable?(path)
2014-09-02 18:07:02 +05:30
tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path}))
tail_output.split("\n")
end
def self.build
2020-11-24 15:15:51 +05:30
Gitlab::SafeRequestStore[self.cache_key] ||=
2022-03-02 08:16:31 +05:30
new(self.full_log_path, level: log_level)
end
def self.log_level(fallback: ::Logger::DEBUG)
ENV.fetch('GITLAB_LOG_LEVEL', fallback)
2018-03-17 18:26:18 +05:30
end
def self.full_log_path
Rails.root.join("log", file_name)
end
def self.cache_key
2019-12-04 20:38:33 +05:30
'logger:' + self.full_log_path.to_s
2014-09-02 18:07:02 +05:30
end
end
end