Skip to content

Commit 05a9ad8

Browse files
committed
Return result of the block when a block is passed to Logger#tag
1 parent bbba73a commit 05a9ad8

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 1.2.8
22

33
* Add `Logger#untagged` to remove previously set logging tags from a block.
4+
* Return result of the block when a block is passed to `Logger#tag`.
45

56
## 1.2.7
67

lib/lumberjack/logger.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,11 @@ def tag(tags, &block)
361361
push_thread_local_value(:lumberjack_logger_tags, merged_tags, &block)
362362
elsif thread_tags
363363
thread_tags.merge!(tags)
364+
nil
364365
else
365366
@tags.merge!(tags)
367+
nil
366368
end
367-
nil
368369
end
369370

370371
# Remove a tag from the current tag context. If this is called inside a block to a

spec/logger_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@
544544
expect(logger.tags).to eq("foo" => "bar", "other" => 1)
545545
end
546546
end
547+
548+
it "should return the result of the block" do
549+
result = logger.tag(tag: 1) { :foo }
550+
expect(result).to eq :foo
551+
end
547552
end
548553

549554
describe "untagged" do
@@ -598,6 +603,11 @@
598603
expect(logger.tags).to eq({"foo" => "bar"})
599604
end
600605
end
606+
607+
it "should return the result of the block" do
608+
result = logger.untagged { :foo }
609+
expect(result).to eq :foo
610+
end
601611
end
602612

603613
describe "log helper methods" do

spec/lumberjack_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
expect(Lumberjack.context_tags).to eq("fog" => "bar")
5656
end
5757
end
58+
59+
it "should return the result of the context block" do
60+
result = Lumberjack.context { :foo }
61+
expect(result).to eq :foo
62+
end
63+
64+
it "should return the result of the use_context block" do
65+
result = Lumberjack.use_context(nil) { :foo }
66+
expect(result).to eq :foo
67+
end
5868
end
5969

6070
describe "unit of work" do

0 commit comments

Comments
 (0)