From a898d6a02a28406bfd0033a5e4d044a0ecbe71f9 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 31 Jan 2017 15:44:46 -0500 Subject: [PATCH] FIX: silence and quiet logger not thread safe This caused info/warning to be consistently missing in dev mode when using puma --- Gemfile.lock | 4 ++-- config/initializers/100-quiet_logger.rb | 12 +++++++++--- config/initializers/100-silence_logger.rb | 9 ++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e492b12e8d8..7ac4aa416fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/config/initializers/100-quiet_logger.rb b/config/initializers/100-quiet_logger.rb index 55488afae94..55c0dfcb4ce 100644 --- a/config/initializers/100-quiet_logger.rb +++ b/config/initializers/100-quiet_logger.rb @@ -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 diff --git a/config/initializers/100-silence_logger.rb b/config/initializers/100-silence_logger.rb index 4040d5dfb4b..9952c8b36ea 100644 --- a/config/initializers/100-silence_logger.rb +++ b/config/initializers/100-silence_logger.rb @@ -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