diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c7650d..3a681bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/lumberjack/logger.rb b/lib/lumberjack/logger.rb index ea475ec..37ffdbd 100644 --- a/lib/lumberjack/logger.rb +++ b/lib/lumberjack/logger.rb @@ -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 diff --git a/spec/logger_spec.rb b/spec/logger_spec.rb index f50260f..85c02a5 100644 --- a/spec/logger_spec.rb +++ b/spec/logger_spec.rb @@ -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 @@ -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 diff --git a/spec/lumberjack_spec.rb b/spec/lumberjack_spec.rb index cdc9cc2..9408a78 100644 --- a/spec/lumberjack_spec.rb +++ b/spec/lumberjack_spec.rb @@ -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