diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-06-20 13:21:27 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-06-20 13:22:11 -0700 |
commit | b9f9951d5f7e6f2c947c292a929a48d41c529f26 (patch) | |
tree | 7fa35c1a38b01a05e6502077fc7d0e94a6d48f0b /activesupport/lib | |
parent | c1c4ecb9dbf40ca8118d5c1c1053b158fe867229 (diff) | |
download | rails-b9f9951d5f7e6f2c947c292a929a48d41c529f26.tar.gz rails-b9f9951d5f7e6f2c947c292a929a48d41c529f26.tar.bz2 rails-b9f9951d5f7e6f2c947c292a929a48d41c529f26.zip |
use thread local queues.
Log listener is a singleton shared across threads, so make sure the
event queues are local to each thread.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/log_subscriber.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb index 8c3921c423..384c56cd5a 100644 --- a/activesupport/lib/active_support/log_subscriber.rb +++ b/activesupport/lib/active_support/log_subscriber.rb @@ -87,7 +87,7 @@ module ActiveSupport end def initialize - @event_stack = [] + @queue_key = [self.class.name, object_id].join "-" super end @@ -99,17 +99,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 +142,11 @@ module ActiveSupport bold = bold ? BOLD : "" "#{bold}#{color}#{text}#{CLEAR}" end + + private + + def event_stack + Thread.current[@queue_key] ||= [] + end end end |