Better way of suppressing render_partial logs

This commit is contained in:
Akira Matsuda 2016-07-05 16:49:40 +09:00
parent 76a3f4cfe9
commit 0fcfad2030
1 changed files with 3 additions and 25 deletions

View File

@ -140,32 +140,10 @@ module Kaminari
undef :to_s
# Redefining to_s not to log each render_partial
def to_s #:nodoc:
subscriber = ActionView::LogSubscriber.log_subscribers.detect {|ls| ls.is_a? ActionView::LogSubscriber}
# There is a logging subscriber
# and we don't want it to log render_partial
# It is threadsafe, but might not repress logging
# consistently in a high-load environment
if subscriber
unless defined? subscriber.render_partial_with_logging
class << subscriber
alias_method :render_partial_with_logging, :render_partial
attr_accessor :render_without_logging
# ugly hack to make a renderer where
# we can turn logging on or off
def render_partial(event)
render_partial_with_logging(event) unless render_without_logging
end
end
end
subscriber.render_without_logging = true
ret = super @window_options.merge :paginator => self
subscriber.render_without_logging = false
ret
if (logger = ActionView::Base.logger)
logger.silence { super @window_options.merge paginator: self }
else
super @window_options.merge :paginator => self
super @window_options.merge paginator: self
end
end
end