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
|
2018-12-05 23:21:45 +05:30
|
|
|
Gitlab::SafeRequestStore[self.cache_key] ||= new(self.full_log_path)
|
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
|