2012-05-26 06:37:49 -04:00
|
|
|
module Gitlab
|
2012-07-17 01:23:16 -04:00
|
|
|
class Logger < ::Logger
|
2014-10-04 11:09:06 -04:00
|
|
|
def self.file_name
|
|
|
|
file_name_noext + '.log'
|
|
|
|
end
|
|
|
|
|
2012-05-21 16:17:41 -04:00
|
|
|
def self.error(message)
|
2012-07-17 01:23:16 -04:00
|
|
|
build.error(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.info(message)
|
|
|
|
build.info(message)
|
2012-05-21 16:17:41 -04:00
|
|
|
end
|
2012-07-05 14:59:37 -04:00
|
|
|
|
|
|
|
def self.read_latest
|
2017-10-19 02:41:55 -04:00
|
|
|
path = self.full_log_path
|
2012-07-17 01:23:16 -04:00
|
|
|
|
2017-08-22 17:09:45 -04:00
|
|
|
return [] unless File.readable?(path)
|
|
|
|
|
2014-02-25 06:12:09 -05:00
|
|
|
tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path}))
|
|
|
|
tail_output.split("\n")
|
2012-12-18 23:14:05 -05:00
|
|
|
end
|
|
|
|
|
2012-07-17 01:23:16 -04:00
|
|
|
def self.build
|
2017-10-19 02:41:55 -04:00
|
|
|
RequestStore[self.cache_key] ||= new(self.full_log_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.full_log_path
|
|
|
|
Rails.root.join("log", file_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.cache_key
|
|
|
|
'logger:'.freeze + self.full_log_path.to_s
|
2012-07-17 01:23:16 -04:00
|
|
|
end
|
2012-05-21 16:17:41 -04:00
|
|
|
end
|
|
|
|
end
|