Skip to content

Commit c2694bb

Browse files
committed
Use Rails logger by default again
Before v2.2.0, `Raven.configuration.logger` was nil if there was no logger configured; now it's always an instance of `Raven::Logger`. This means that the `||=` assignment in the railtie no longer has any effect. If we unconditionally set the logger in a `before_initialize` hook, apps will still be able to configure their own logger in an initializer, but the Rails logger will be used by default again if they don't. There's an existing test which covers this behaviour, but the logger was being set to false before it ran, which doesn't accurately reflect the default configuration any more. Instead of trying to reset the logger before the test, we can temporarily swap in a new configuration object.
1 parent c5a89c2 commit c2694bb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/raven/integrations/rails.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ class Rails < ::Rails::Railtie
3232
end
3333
end
3434

35+
config.before_initialize do
36+
Raven.configuration.logger = ::Rails.logger
37+
end
38+
3539
config.after_initialize do
3640
Raven.configure do |config|
3741
config.project_root ||= ::Rails.root
38-
config.logger ||= ::Rails.logger
3942
config.release ||= config.detect_release # if project_root has changed, need to re-check
4043
end
4144

spec/raven/integrations/rails_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@
66

77
describe TestApp, :type => :request do
88
before(:all) do
9-
Raven.configure do |config|
9+
@original_configuration = Raven.configuration
10+
11+
Raven.configuration = Raven::Configuration.new.tap do |config|
1012
config.dsn = 'dummy://12345:[email protected]:3000/sentry/42'
1113
config.encoding = 'json'
12-
config.logger = false
1314
end
15+
1416
Rails.logger = Logger.new(nil)
1517
Rails.env = "production"
1618
TestApp.initialize!
1719
end
1820

21+
after(:all) do
22+
Raven.configuration = @original_configuration
23+
end
24+
1925
after(:each) do
2026
Raven.client.transport.events = []
2127
end

0 commit comments

Comments
 (0)