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
This commit is contained in:
commit
bf4e97fc83
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Memoize GitLab logger to reduce open file descriptors
|
||||||
|
merge_request:
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -13,7 +13,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.read_latest
|
def self.read_latest
|
||||||
path = Rails.root.join("log", file_name)
|
path = self.full_log_path
|
||||||
|
|
||||||
return [] unless File.readable?(path)
|
return [] unless File.readable?(path)
|
||||||
|
|
||||||
|
@ -22,7 +22,15 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
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
|
Loading…
Reference in New Issue