Skip to content

Commit

Permalink
Return result of the block when a block is passed to Logger#tag
Browse files Browse the repository at this point in the history
  • Loading branch information
bdurand committed Aug 29, 2020
1 parent bbba73a commit 05a9ad8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.2.8

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

## 1.2.7

Expand Down
3 changes: 2 additions & 1 deletion lib/lumberjack/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,11 @@ def tag(tags, &block)
push_thread_local_value(:lumberjack_logger_tags, merged_tags, &block)
elsif thread_tags
thread_tags.merge!(tags)
nil
else
@tags.merge!(tags)
nil
end
nil
end

# Remove a tag from the current tag context. If this is called inside a block to a
Expand Down
10 changes: 10 additions & 0 deletions spec/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@
expect(logger.tags).to eq("foo" => "bar", "other" => 1)
end
end

it "should return the result of the block" do
result = logger.tag(tag: 1) { :foo }
expect(result).to eq :foo
end
end

describe "untagged" do
Expand Down Expand Up @@ -598,6 +603,11 @@
expect(logger.tags).to eq({"foo" => "bar"})
end
end

it "should return the result of the block" do
result = logger.untagged { :foo }
expect(result).to eq :foo
end
end

describe "log helper methods" do
Expand Down
10 changes: 10 additions & 0 deletions spec/lumberjack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
expect(Lumberjack.context_tags).to eq("fog" => "bar")
end
end

it "should return the result of the context block" do
result = Lumberjack.context { :foo }
expect(result).to eq :foo
end

it "should return the result of the use_context block" do
result = Lumberjack.use_context(nil) { :foo }
expect(result).to eq :foo
end
end

describe "unit of work" do
Expand Down

0 comments on commit 05a9ad8

Please sign in to comment.