diff options
Diffstat (limited to 'activesupport/lib/active_support/log_subscriber.rb')
-rw-r--r-- | activesupport/lib/active_support/log_subscriber.rb | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb index 8c3921c423..e5b4ca2738 100644 --- a/activesupport/lib/active_support/log_subscriber.rb +++ b/activesupport/lib/active_support/log_subscriber.rb @@ -58,7 +58,6 @@ module ActiveSupport def attach_to(namespace, log_subscriber=new, notifier=ActiveSupport::Notifications) log_subscribers << log_subscriber - @@flushable_loggers = nil log_subscriber.public_methods(false).each do |event| next if %w{ start finish }.include?(event.to_s) @@ -71,23 +70,14 @@ module ActiveSupport @@log_subscribers ||= [] end - def flushable_loggers - @@flushable_loggers ||= begin - loggers = log_subscribers.map(&:logger) - loggers.uniq! - loggers.select! { |l| l.respond_to?(:flush) } - loggers - end - end - # Flush all log_subscribers' logger. def flush_all! - flushable_loggers.each { |log| log.flush } + logger.flush if logger.respond_to?(:flush) end end def initialize - @event_stack = [] + @queue_key = [self.class.name, object_id].join "-" super end @@ -99,17 +89,17 @@ module ActiveSupport return unless logger e = ActiveSupport::Notifications::Event.new(name, Time.now, nil, id, payload) - parent = @event_stack.last + parent = event_stack.last parent << e if parent - @event_stack.push e + event_stack.push e end def finish(name, id, payload) return unless logger finished = Time.now - event = @event_stack.pop + event = event_stack.pop event.end = finished event.payload.merge!(payload) @@ -142,5 +132,11 @@ module ActiveSupport bold = bold ? BOLD : "" "#{bold}#{color}#{text}#{CLEAR}" end + + private + + def event_stack + Thread.current[@queue_key] ||= [] + end end end |