aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-06-04 09:48:29 -0700
committerwycats <wycats@gmail.com>2010-06-04 20:11:05 -0700
commit5fa3a2d12395ce1d7188c3b7dcb5d616e77eb5dd (patch)
treef00c513d042fc5285443474c3d9290d3a4b66c21 /railties/lib/rails
parent220603ee70d1655cf97a1e9f09fbc5d019c99856 (diff)
downloadrails-5fa3a2d12395ce1d7188c3b7dcb5d616e77eb5dd.tar.gz
rails-5fa3a2d12395ce1d7188c3b7dcb5d616e77eb5dd.tar.bz2
rails-5fa3a2d12395ce1d7188c3b7dcb5d616e77eb5dd.zip
Improve performance of the log subscriber by remembering the list of all loggers instead of trying to extract them each time
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/log_subscriber.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/railties/lib/rails/log_subscriber.rb b/railties/lib/rails/log_subscriber.rb
index 145c7e0ace..9a74fee745 100644
--- a/railties/lib/rails/log_subscriber.rb
+++ b/railties/lib/rails/log_subscriber.rb
@@ -52,6 +52,7 @@ module Rails
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 @@ module Rails
@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.