aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2012-09-26 10:08:20 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2012-09-27 10:46:50 -0700
commit20f5f08d3b4df0f31099378c8178a9a78db52419 (patch)
treec6a1bf0ad5520df075bab80f28f119ee7dd748d6 /activesupport/test
parent032c2b6b548f21ea938e3ada281a23e87f5173b7 (diff)
downloadrails-20f5f08d3b4df0f31099378c8178a9a78db52419.tar.gz
rails-20f5f08d3b4df0f31099378c8178a9a78db52419.tar.bz2
rails-20f5f08d3b4df0f31099378c8178a9a78db52419.zip
Add logger.push_tags and .pop_tags to complement logger.tagged
Avoid memory leak from unflushed logs on other threads leaving tags behind. Conflicts: activesupport/CHANGELOG.md activesupport/lib/active_support/tagged_logging.rb activesupport/test/tagged_logging_test.rb
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/tagged_logging_test.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb
index c838c073e6..7253eb1222 100644
--- a/activesupport/test/tagged_logging_test.rb
+++ b/activesupport/test/tagged_logging_test.rb
@@ -29,6 +29,33 @@ class TaggedLoggingTest < ActiveSupport::TestCase
assert_equal "[BCX] [Jason] [New] Funky time\n", @output.string
end
+ test "tagged are flattened" do
+ @logger.tagged("BCX", %w(Jason New)) { @logger.info "Funky time" }
+ assert_equal "[BCX] [Jason] [New] Funky time\n", @output.string
+ end
+
+ test "push and pop tags directly" do
+ assert_equal %w(A B C), @logger.push_tags('A', ['B', ' ', ['C']])
+ @logger.info 'a'
+ assert_equal %w(C), @logger.pop_tags
+ @logger.info 'b'
+ assert_equal %w(B), @logger.pop_tags(1)
+ @logger.info 'c'
+ assert_equal [], @logger.clear_tags!
+ @logger.info 'd'
+ assert_equal "[A] [B] [C] a\n[A] [B] b\n[A] c\nd\n", @output.string
+ end
+
+ test "does not strip message content" do
+ @logger.info " Hello"
+ assert_equal " Hello\n", @output.string
+ end
+
+ test "provides access to the logger instance" do
+ @logger.tagged("BCX") { |logger| logger.info "Funky time" }
+ assert_equal "[BCX] Funky time\n", @output.string
+ end
+
test "tagged once with blank and nil" do
@logger.tagged(nil, "", "New") { @logger.info "Funky time" }
assert_equal "[New] Funky time\n", @output.string