提交 5fa3a2d1 编写于 作者: W wycats

Improve performance of the log subscriber by remembering the list of all...

Improve performance of the log subscriber by remembering the list of all loggers instead of trying to extract them each time
上级 220603ee
......@@ -52,6 +52,7 @@ class LogSubscriber
def self.add(namespace, log_subscriber, notifier = ActiveSupport::Notifications)
log_subscribers << log_subscriber
@flushable_loggers = nil
log_subscriber.public_methods(false).each do |event|
notifier.subscribe("#{event}.#{namespace}") do |*args|
......@@ -70,11 +71,17 @@ def self.log_subscribers
@log_subscribers ||= []
end
def self.flushable_loggers
@flushable_loggers ||= begin
loggers = log_subscribers.map(&:logger)
loggers.uniq!
loggers.select { |l| l.respond_to?(:flush) }
end
end
# Flush all log_subscribers' logger.
def self.flush_all!
loggers = log_subscribers.map(&:logger)
loggers.uniq!
loggers.each { |l| l.flush if l.respond_to?(:flush) }
flushable_loggers.each(&:flush)
end
# By default, we use the Rails.logger for logging.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册