提交 eed68fdd 编写于 作者: R Rafael Mendonça França

Merge pull request #9065 from atombender/master

Fix TaggedLogging to allow loggers to be instantiated multiple times without having to share the stack of tags
......@@ -43,7 +43,9 @@ def clear_tags!
end
def current_tags
Thread.current[:activesupport_tagged_logging_tags] ||= []
# We use our object ID here to void conflicting with other instances
thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}".freeze
Thread.current[thread_key] ||= []
end
private
......
......@@ -79,6 +79,19 @@ def flush(*)
assert_equal "[OMG] Cool story bro\n[BCX] Funky time\n", @output.string
end
test "keeps each tag in their own instance" do
@other_output = StringIO.new
@other_logger = ActiveSupport::TaggedLogging.new(MyLogger.new(@other_output))
@logger.tagged("OMG") do
@other_logger.tagged("BCX") do
@logger.info "Cool story bro"
@other_logger.info "Funky time"
end
end
assert_equal "[OMG] Cool story bro\n", @output.string
assert_equal "[BCX] Funky time\n", @other_output.string
end
test "cleans up the taggings on flush" do
@logger.tagged("BCX") do
Thread.new do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册