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
This commit is contained in:
Rafael Mendonça França 2015-01-02 19:55:29 -03:00
commit eed68fddee
2 changed files with 16 additions and 1 deletions

@ -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