gitlab-org--gitlab-foss/lib/gitlab/logger.rb
Michael Kozono a54a5d9f39 Use Gitlab::SafeRequestStore in more places
Even if it doesn’t save lines of code, since people will tend to use
code they’ve seen. And `SafeRequestStore` is safer since you
don’t have to remember to check `RequestStore.active?`.
2018-09-24 12:11:27 -07:00

44 lines
835 B
Ruby

module Gitlab
class Logger < ::Logger
def self.file_name
file_name_noext + '.log'
end
def self.debug(message)
build.debug(message)
end
def self.error(message)
build.error(message)
end
def self.warn(message)
build.warn(message)
end
def self.info(message)
build.info(message)
end
def self.read_latest
path = self.full_log_path
return [] unless File.readable?(path)
tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path}))
tail_output.split("\n")
end
def self.build
Gitlab::SafeRequestStore[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
end
end
end