Skip to content

Commit

Permalink
Add test for passing multiple context providers to logger initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
wjlroe committed Aug 6, 2024
1 parent 5e169d5 commit 3eb4d5e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/logger_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,31 @@
assert_equal 'my-context-id', log[:context][:id]
end

it "should be able to add contextual information to events with multiple context providers" do
provider_1 = -> { { 'context' => { 'id' => 'my-context-id' } } }
provider_2 = -> { { 'context' => { 'type' => 'test' } } }
purchase_logger = Twiglet::Logger.new(
'petshop',
now: @now,
output: @buffer,
context_providers: [provider_1, provider_2]
)

# do stuff
purchase_logger.info(
{
message: 'customer bought a dog',
pet: { name: 'Barker', species: 'dog', breed: 'Bitsa' }
}
)

log = read_json @buffer

assert_equal 'customer bought a dog', log[:message]
assert_equal 'my-context-id', log[:context][:id]
assert_equal 'test', log[:context][:type]
end

it "chaining .with and .context_provider is possible" do
# Let's add some context to this customer journey
purchase_logger = @logger.with(
Expand Down

0 comments on commit 3eb4d5e

Please sign in to comment.