Revert "Cleaner log silencer with Module#prepend"
Andrew Kane
committed Mar 23, 2016
commit 8b43417d92b0d9420fba5fb53ccd81c7127bd59b
Showing 3
changed files with
20 additions
and 19 deletions
ahoy.rb b/lib/ahoy.rb
+0
-1
| @@ | @@ -27,7 +27,6 @@ require "ahoy/stores/fluentd_store" |
| require "ahoy/stores/mongoid_store" | |
| require "ahoy/stores/kinesis_firehose_store" | |
| require "ahoy/stores/bunny_store" | |
| - | require "ahoy/log_silencer" |
| require "ahoy/engine" | |
| require "ahoy/warden" if defined?(Warden) | |
ahoy/engine.rb b/lib/ahoy/engine.rb
+20
-2
| @@ | @@ -1,12 +1,30 @@ |
| module Ahoy | |
| class Engine < ::Rails::Engine | |
| initializer "ahoy.middleware", after: "sprockets.environment" do |app| | |
| - | Rails::Rack::Logger.send(:prepend, Ahoy::LogSilencer) if Ahoy.quiet |
| - | |
| if Ahoy.throttle | |
| require "ahoy/throttle" | |
| app.middleware.use Ahoy::Throttle | |
| end | |
| + | |
| + | next unless Ahoy.quiet |
| + | |
| + | # Parse PATH_INFO by assets prefix |
| + | AHOY_PREFIX = "/ahoy/".freeze |
| + | |
| + | # Just create an alias for call in middleware |
| + | Rails::Rack::Logger.class_eval do |
| + | def call_with_quiet_ahoy(env) |
| + | if env["PATH_INFO"].start_with?(AHOY_PREFIX) && logger.respond_to?(:silence_logger) |
| + | logger.silence_logger do |
| + | call_without_quiet_ahoy(env) |
| + | end |
| + | else |
| + | call_without_quiet_ahoy(env) |
| + | end |
| + | end |
| + | alias_method :call_without_quiet_ahoy, :call |
| + | alias_method :call, :call_with_quiet_ahoy |
| + | end |
| end | |
| end | |
| end | |
ahoy/log_silencer.rb b/lib/ahoy/log_silencer.rb
+0
-16
| @@ | @@ -1,16 +0,0 @@ |
| - | module Ahoy |
| - | module LogSilencer |
| - | PATH_INFO = "PATH_INFO".freeze |
| - | AHOY_PREFIX = "/ahoy/".freeze |
| - | |
| - | def call(env) |
| - | if env[PATH_INFO].start_with?(AHOY_PREFIX) && logger.respond_to?(:silence_logger) |
| - | logger.silence_logger do |
| - | super |
| - | end |
| - | else |
| - | super |
| - | end |
| - | end |
| - | end |
| - | end |