提交 b9f9951d 编写于 作者: A Aaron Patterson

use thread local queues.

Log listener is a singleton shared across threads, so make sure the
event queues are local to each thread.
上级 c1c4ecb9
......@@ -87,7 +87,7 @@ def flush_all!
end
def initialize
@event_stack = []
@queue_key = [self.class.name, object_id].join "-"
super
end
......@@ -99,17 +99,17 @@ def start(name, id, payload)
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 @@ def color(text, color, bold=false)
bold = bold ? BOLD : ""
"#{bold}#{color}#{text}#{CLEAR}"
end
private
def event_stack
Thread.current[@queue_key] ||= []
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册