Skip to content

Commit

Permalink
{config,loggable}: set default Logger level to Logger::WARN
Browse files Browse the repository at this point in the history
Issue #550 mentions that README states that our default logger is `Logger::WARN`,
however the code never sets that level. The default value is `Logger::DEBUG`,
which is unwanted, since it generates a lot of clutter.
  • Loading branch information
kyrylo committed Feb 10, 2020
1 parent fe27992 commit a0a3e9f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Airbrake Ruby Changelog
```
ERROR -- : **Airbrake: tdigest.count=94, but count=100
```
* Fixed `Airbrake::Loggable` and `Airbrake::Config.instance.logger` not being
set to `Logger::WARN` by default (as promised by the README)
([#551](https://github.com/airbrake/airbrake-ruby/pull/551))

### [v4.13.0][v4.13.0] (January 27, 2020)

Expand Down
4 changes: 3 additions & 1 deletion lib/airbrake-ruby/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ def instance

# @param [Hash{Symbol=>Object}] user_config the hash to be used to build the
# config
# rubocop:disable Metrics/AbcSize
def initialize(user_config = {})
self.proxy = {}
self.queue_size = 100
self.workers = 1
self.code_hunks = true
self.logger = ::Logger.new(File::NULL)
self.logger = ::Logger.new(File::NULL).tap { |l| l.level = Logger::WARN }
self.project_id = user_config[:project_id]
self.project_key = user_config[:project_key]
self.host = 'https://api.airbrake.io'
Expand All @@ -149,6 +150,7 @@ def initialize(user_config = {})

merge(user_config)
end
# rubocop:enable Metrics/AbcSize

# The full URL to the Airbrake Notice API. Based on the +:host+ option.
# @return [URI] the endpoint address
Expand Down
2 changes: 1 addition & 1 deletion lib/airbrake-ruby/loggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class << self

# @return [Logger]
def instance
@instance ||= ::Logger.new(File::NULL)
@instance ||= ::Logger.new(File::NULL).tap { |l| l.level = ::Logger::WARN }
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,10 @@
end
end
end

describe "#logger" do
it "sets logger level to Logger::WARN" do
expect(subject.logger.level).to eq(Logger::WARN)
end
end
end
17 changes: 17 additions & 0 deletions spec/loggable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RSpec.describe Airbrake::Loggable do
describe ".instance" do
it "returns a logger" do
expect(described_class.instance).to be_a(Logger)
end
end

describe "#logger" do
let(:subject) do
Class.new { include Airbrake::Loggable }.new
end

it "returns a logger that has Logger::WARN severity" do
expect(subject.logger.level).to eq(Logger::WARN)
end
end
end

0 comments on commit a0a3e9f

Please sign in to comment.