Skip to content

Commit

Permalink
Fix ActiveSupport Logger broadcast compatibility
Browse files Browse the repository at this point in the history
We were using `progname` instead of group in the AppSignal Logger `add`
method. Making the convenience methods such as `warn`, `info`, etc. Not
logging anything when called as in:

```ruby
Rails.logger.warn("Warning message")
```

This commits updates that to use `group` instead of `progname` as in the
original Ruby Logger implementation.

Co-authored-by: Jörg Schiller <joergschiller@googlemail.com>
  • Loading branch information
luismiramirez and joergschiller committed Jun 2, 2023
1 parent 05dc9fe commit 1750072
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .changesets/fix-activesupport-logger-broadcast-compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
bump: "patch"
type: "fix"
---

Fixed a bug that prevented log messages from getting to AppSignal when using the convenience methods as in:

```ruby
Rails.logger.warn("Warning message")
```
2 changes: 1 addition & 1 deletion lib/appsignal/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def add(severity, message = nil, group = nil)
if block_given?
message = yield
else
message = progname
message = group
group = @group
end
end
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/appsignal/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
logger.add(::Logger::INFO, "Log message", "other_group")
end

it "should return with a nil message" do
expect(Appsignal::Extension).not_to receive(:log)
logger.add(::Logger::INFO, nil)
it "should log when using `group` for the log message" do
expect(Appsignal::Extension).to receive(:log)
.with("group", 3, 0, "Log message", instance_of(Appsignal::Extension::Data))
logger.add(::Logger::INFO, nil, "Log message")
end

context "with info log level" do
Expand Down

0 comments on commit 1750072

Please sign in to comment.