Skip to content

Commit

Permalink
Ensure the log line attributes take priority
Browse files Browse the repository at this point in the history
This commit does not change the implementation, which already did
this, but writes a test to ensure this behaviour and specifies it
in the changelog.
  • Loading branch information
unflxw committed Nov 12, 2024
1 parent 1c42ca3 commit b265c88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .changesets/add-default-attributes-to-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ bump: patch
type: add
---

Add default attributes to Logger
Allow for default attributes to be given when initialising an AppSignal `Logger` instance:

```ruby
order_logger = Appsignal::Logger.new("app", attributes: { order_id: 123 })
```

All log lines reported by this logger will contain the given attribute. Attributes given when reporting the log line will be merged with the default attributes for the logger, with those in the log line taking priority.
9 changes: 9 additions & 0 deletions spec/lib/appsignal/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@
expect(default_attributes).to eq({ :some_key => "some_value" })
expect(line_attributes).to eq({ :other_key => "other_value" })
end

it "prioritises line attributes over default attributes" do
logger = Appsignal::Logger.new("group", :attributes => { :some_key => "some_value" })

expect(Appsignal::Extension).to receive(:log).with("group", 6, 0, "Some message",
Appsignal::Utils::Data.generate({ :some_key => "other_value" }))

logger.error("Some message", { :some_key => "other_value" })
end
end

describe "#error with exception object" do
Expand Down

0 comments on commit b265c88

Please sign in to comment.