提交 bf4e97fc 编写于 作者: N Nick Thomas

Merge branch 'sh-memoize-logger' into 'master'

Memoize GitLab logger to reduce open file descriptors

Closes gitlab-ee#3664

See merge request gitlab-org/gitlab-ce!15007
---
title: Memoize GitLab logger to reduce open file descriptors
merge_request:
author:
type: fixed
......@@ -13,7 +13,7 @@ module Gitlab
end
def self.read_latest
path = Rails.root.join("log", file_name)
path = self.full_log_path
return [] unless File.readable?(path)
......@@ -22,7 +22,15 @@ module Gitlab
end
def self.build
new(Rails.root.join("log", file_name))
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
require 'spec_helper'
describe Gitlab::AppLogger, :request_store do
subject { described_class }
it 'builds a logger once' do
expect(::Logger).to receive(:new).and_call_original
subject.info('hello world')
subject.error('hello again')
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册