aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-19 03:10:47 -0700
committerJosé Valim <jose.valim@gmail.com>2012-03-19 03:10:47 -0700
commit98dc67cf5af5ae9516a047950e63eb4d6dde27ef (patch)
tree51d726d54ea148da6db030bf54a3bc15af8d2573
parent24d244c1bc1a744de599df18d74c9b343fd4c9fe (diff)
parente0ee14ed2305a0b2e6ee53c5d5a98450d2f534e4 (diff)
downloadrails-98dc67cf5af5ae9516a047950e63eb4d6dde27ef.tar.gz
rails-98dc67cf5af5ae9516a047950e63eb4d6dde27ef.tar.bz2
rails-98dc67cf5af5ae9516a047950e63eb4d6dde27ef.zip
Merge pull request #5508 from FND/tagged_logger_shortcut
Provide access to logger instance within TaggedLogging blocks
-rw-r--r--activesupport/lib/active_support/tagged_logging.rb2
-rw-r--r--activesupport/test/tagged_logging_test.rb7
2 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb
index 88fd438448..538a36f6d9 100644
--- a/activesupport/lib/active_support/tagged_logging.rb
+++ b/activesupport/lib/active_support/tagged_logging.rb
@@ -45,7 +45,7 @@ module ActiveSupport
tags = formatter.current_tags
new_tags = new_tags.flatten.reject(&:blank?)
tags.concat new_tags
- yield
+ yield self
ensure
tags.pop(new_tags.size)
end
diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb
index dd4ae319e5..0751c2469e 100644
--- a/activesupport/test/tagged_logging_test.rb
+++ b/activesupport/test/tagged_logging_test.rb
@@ -18,7 +18,7 @@ class TaggedLoggingTest < ActiveSupport::TestCase
@logger.tagged("BCX") { @logger.info "Funky time" }
assert_equal "[BCX] Funky time\n", @output.string
end
-
+
test "tagged twice" do
@logger.tagged("BCX") { @logger.tagged("Jason") { @logger.info "Funky time" } }
assert_equal "[BCX] [Jason] Funky time\n", @output.string
@@ -29,6 +29,11 @@ class TaggedLoggingTest < ActiveSupport::TestCase
assert_equal "[BCX] [Jason] [New] Funky time\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