diff --git a/lib/ldclient-rb/config.rb b/lib/ldclient-rb/config.rb index 052d4ce0..7c2642be 100644 --- a/lib/ldclient-rb/config.rb +++ b/lib/ldclient-rb/config.rb @@ -458,7 +458,7 @@ def self.default_connect_timeout # @return [Logger] the Rails logger if in Rails, or a default Logger at WARN level otherwise # def self.default_logger - if defined?(Rails) && Rails.respond_to?(:logger) + if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger Rails.logger else log = ::Logger.new($stdout) diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 8c6c28ac..fcbd7df3 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -49,6 +49,11 @@ module LaunchDarkly stub_const("Rails", rails) expect(subject.default_logger).to eq :logger end + it "uses logger if Rails logger is nil" do + rails = instance_double("Rails", logger: nil) + stub_const("Rails", rails) + expect(subject.default_logger).to be_an_instance_of Logger + end it "Uses logger if Rails is not available" do expect(subject.default_logger).to be_an_instance_of Logger end