提交 e0ee14ed 编写于 作者: F FND

Provide access to logger instance within TaggedLogging blocks

this improves encapsulation, simplifying occurrences like the following:

    Rails.logger.tagged("DEBUG") { Rails.logger.debug(msg) }

... by removing the need to rely on (i.e. repeat) outer variables:

    Rails.logger.tagged("DEBUG") { |logger| logger.debug(msg) }
上级 24d244c1
......@@ -45,7 +45,7 @@ def tagged(*new_tags)
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
......
......@@ -18,7 +18,7 @@ def flush(*)
@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 @@ def flush(*)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册