aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/tagged_logging_test.rb
diff options
context:
space:
mode:
authorThierry Joyal <thierry.joyal@gmail.com>2017-01-24 12:48:43 +0000
committerThierry Joyal <thierry.joyal@gmail.com>2017-02-27 21:01:30 +0000
commit62fba74932a72ee8104712a3db432b593fe0c6af (patch)
tree8aec22292596886a1a0dac60cb57c0fd47967b20 /activesupport/test/tagged_logging_test.rb
parent4cc1c14493e7a9bd188ee13c237366f6bc2e13f4 (diff)
downloadrails-62fba74932a72ee8104712a3db432b593fe0c6af.tar.gz
rails-62fba74932a72ee8104712a3db432b593fe0c6af.tar.bz2
rails-62fba74932a72ee8104712a3db432b593fe0c6af.zip
TaggedLogging to return a new logger instance
Diffstat (limited to 'activesupport/test/tagged_logging_test.rb')
-rw-r--r--activesupport/test/tagged_logging_test.rb29
1 files changed, 21 insertions, 8 deletions
diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb
index 2469e827d4..87940472b4 100644
--- a/activesupport/test/tagged_logging_test.rb
+++ b/activesupport/test/tagged_logging_test.rb
@@ -17,9 +17,10 @@ class TaggedLoggingTest < ActiveSupport::TestCase
test "sets logger.formatter if missing and extends it with a tagging API" do
logger = Logger.new(StringIO.new)
assert_nil logger.formatter
- ActiveSupport::TaggedLogging.new(logger)
- assert_not_nil logger.formatter
- assert logger.formatter.respond_to?(:tagged)
+
+ other_logger = ActiveSupport::TaggedLogging.new(logger)
+ assert_not_nil other_logger.formatter
+ assert other_logger.formatter.respond_to?(:tagged)
end
test "tagged once" do
@@ -80,16 +81,28 @@ class TaggedLoggingTest < ActiveSupport::TestCase
end
test "keeps each tag in their own instance" do
- @other_output = StringIO.new
- @other_logger = ActiveSupport::TaggedLogging.new(MyLogger.new(@other_output))
+ other_output = StringIO.new
+ other_logger = ActiveSupport::TaggedLogging.new(MyLogger.new(other_output))
@logger.tagged("OMG") do
- @other_logger.tagged("BCX") do
+ other_logger.tagged("BCX") do
@logger.info "Cool story"
- @other_logger.info "Funky time"
+ other_logger.info "Funky time"
end
end
assert_equal "[OMG] Cool story\n", @output.string
- assert_equal "[BCX] Funky time\n", @other_output.string
+ assert_equal "[BCX] Funky time\n", other_output.string
+ end
+
+ test "does not share the same formatter instance of the original logger" do
+ other_logger = ActiveSupport::TaggedLogging.new(@logger)
+
+ @logger.tagged("OMG") do
+ other_logger.tagged("BCX") do
+ @logger.info "Cool story"
+ other_logger.info "Funky time"
+ end
+ end
+ assert_equal "[OMG] Cool story\n[BCX] Funky time\n", @output.string
end
test "cleans up the taggings on flush" do