FIX: silence and quiet logger not thread safe

This caused info/warning to be consistently missing
in dev mode when using puma
This commit is contained in:
Sam 2017-01-31 15:44:46 -05:00
parent 614b041272
commit a898d6a02a
3 changed files with 17 additions and 8 deletions

View File

@ -140,7 +140,7 @@ GEM
kgio (2.10.0)
libv8 (5.3.332.38.3)
listen (0.7.3)
logster (1.2.5)
logster (1.2.7)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lru_redux (1.1.0)
@ -476,4 +476,4 @@ DEPENDENCIES
unicorn
BUNDLED WITH
1.13.7
1.14.2

View File

@ -4,14 +4,20 @@ end
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
override = false
if (env['PATH_INFO'].index("/assets/") == 0) or
(env['PATH_INFO'].index("mini-profiler-resources") == 0)
Rails.logger.level = Logger::ERROR
if ::Logster::Logger === Rails.logger
override = true
Rails.logger.override_level = Logger::ERROR
end
end
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
if override
Rails.logger.override_level = nil
end
end
end
alias_method_chain :call, :quiet_assets

View File

@ -12,21 +12,24 @@ class SilenceLogger < Rails::Rack::Logger
end
def call(env)
prev_level = Rails.logger.level
path_info = env[PATH_INFO]
override = false
if env[HTTP_X_SILENCE_LOGGER] ||
@opts[:silenced].include?(path_info) ||
path_info.start_with?('/logs') ||
path_info.start_with?('/user_avatar') ||
path_info.start_with?('/letter_avatar')
Rails.logger.level = Logger::WARN
if ::Logster::Logger === Rails.logger
override = true
Rails.logger.override_level = Logger::WARN
end
@app.call(env)
else
super(env)
end
ensure
Rails.logger.level = prev_level
Rails.logger.override_level = nil if override
end
end