gitlab-org--gitlab-foss/lib/gitlab/logger.rb
Stan Hu 324b3bbaca Memoize GitLab logger to reduce open file descriptors
We see that in gitlab-org/gitlab-ee#3664 that if we log a lot of
data in Sidekiq workers, the number of open file descriptors
reaches over 1000. To avoid this, we can memoize the logger per
thread via RequestStore.

Closes gitlab-org/gitlab-ee#3664
2017-10-24 14:06:23 +03:00

36 lines
697 B
Ruby

module Gitlab
class Logger < ::Logger
def self.file_name
file_name_noext + '.log'
end
def self.error(message)
build.error(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
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
end
end
end