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:
parent
614b041272
commit
a898d6a02a
|
@ -140,7 +140,7 @@ GEM
|
||||||
kgio (2.10.0)
|
kgio (2.10.0)
|
||||||
libv8 (5.3.332.38.3)
|
libv8 (5.3.332.38.3)
|
||||||
listen (0.7.3)
|
listen (0.7.3)
|
||||||
logster (1.2.5)
|
logster (1.2.7)
|
||||||
loofah (2.0.3)
|
loofah (2.0.3)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
lru_redux (1.1.0)
|
lru_redux (1.1.0)
|
||||||
|
@ -476,4 +476,4 @@ DEPENDENCIES
|
||||||
unicorn
|
unicorn
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.13.7
|
1.14.2
|
||||||
|
|
|
@ -4,14 +4,20 @@ end
|
||||||
|
|
||||||
Rails::Rack::Logger.class_eval do
|
Rails::Rack::Logger.class_eval do
|
||||||
def call_with_quiet_assets(env)
|
def call_with_quiet_assets(env)
|
||||||
previous_level = Rails.logger.level
|
|
||||||
|
override = false
|
||||||
if (env['PATH_INFO'].index("/assets/") == 0) or
|
if (env['PATH_INFO'].index("/assets/") == 0) or
|
||||||
(env['PATH_INFO'].index("mini-profiler-resources") == 0)
|
(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
|
end
|
||||||
|
|
||||||
call_without_quiet_assets(env).tap do
|
call_without_quiet_assets(env).tap do
|
||||||
Rails.logger.level = previous_level
|
if override
|
||||||
|
Rails.logger.override_level = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias_method_chain :call, :quiet_assets
|
alias_method_chain :call, :quiet_assets
|
||||||
|
|
|
@ -12,21 +12,24 @@ class SilenceLogger < Rails::Rack::Logger
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
prev_level = Rails.logger.level
|
|
||||||
path_info = env[PATH_INFO]
|
path_info = env[PATH_INFO]
|
||||||
|
override = false
|
||||||
|
|
||||||
if env[HTTP_X_SILENCE_LOGGER] ||
|
if env[HTTP_X_SILENCE_LOGGER] ||
|
||||||
@opts[:silenced].include?(path_info) ||
|
@opts[:silenced].include?(path_info) ||
|
||||||
path_info.start_with?('/logs') ||
|
path_info.start_with?('/logs') ||
|
||||||
path_info.start_with?('/user_avatar') ||
|
path_info.start_with?('/user_avatar') ||
|
||||||
path_info.start_with?('/letter_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)
|
@app.call(env)
|
||||||
else
|
else
|
||||||
super(env)
|
super(env)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
Rails.logger.level = prev_level
|
Rails.logger.override_level = nil if override
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue