Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support report_level configuration just like rollbar.js #958

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/rollbar/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Configuration
attr_accessor :open_timeout
attr_accessor :request_timeout
attr_accessor :net_retries
attr_accessor :report_level
attr_accessor :root
attr_accessor :js_options
attr_accessor :js_enabled
Expand Down Expand Up @@ -122,6 +123,7 @@ def initialize
@js_enabled = false
@js_options = {}
@locals = {}
@report_level = :debug
@scrub_fields = [:passwd, :password, :password_confirmation, :secret,
:confirm_password, :password_confirmation, :secret_token,
:api_key, :access_token, :accessToken, :session_id]
Expand Down
16 changes: 16 additions & 0 deletions lib/rollbar/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ class Notifier
MUTEX = Mutex.new
EXTENSION_REGEXP = /.rollbar\z/.freeze

# helps cache the hierarchy of the report levels from low to high
# as both symbols and strings
REPORT_LEVELS =
begin
h = Hash.new(100) # configure with default of 10

[:debug, :info, :warning, :error, :critical].each_with_index do |level, i|
h[level] = i
h[level.to_s] = i
end

h
end.freeze

def initialize(parent_notifier = nil, payload_options = nil, scope = nil)
if parent_notifier
self.configuration = parent_notifier.configuration.clone
Expand Down Expand Up @@ -130,6 +144,8 @@ def silenced
def log(level, *args)
return 'disabled' unless enabled?

return 'not_reported' if REPORT_LEVELS[level] < REPORT_LEVELS[configuration.report_level]

message, exception, extra, context = extract_arguments(args)
use_exception_level_filters = use_exception_level_filters?(extra)

Expand Down
21 changes: 21 additions & 0 deletions spec/rollbar_bc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@
Rollbar.report_exception(@exception).should == 'disabled'
end

it 'should not report when level is lower than report_level' do
Rollbar.configure do |config|
config.enabled = true
config.report_level = 'error'
end

Rollbar.configuration.report_level.should == 'error'
Rollbar.warning('warning message').should == 'not_reported'
end


it 'should report when level is higher than or equal to report_level' do
Rollbar.configure do |config|
config.report_level = 'error'
end

logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
logger_mock.should_receive(:info).with('[Rollbar] Success')
Rollbar.report_exception(@exception)
end

it 'should stay disabled if configure is called again' do
Rollbar.clear_notifier!

Expand Down