Module: ExceptionNotifier
- Defined in:
- lib/exception_notifier.rb,
lib/exception_notifier/notifier.rb,
lib/exception_notifier/irc_notifier.rb,
lib/exception_notifier/email_notifier.rb,
lib/exception_notifier/slack_notifier.rb,
lib/exception_notifier/hipchat_notifier.rb,
lib/exception_notifier/webhook_notifier.rb,
lib/exception_notifier/campfire_notifier.rb,
lib/exception_notifier/modules/backtrace_cleaner.rb
Defined Under Namespace
Modules: BacktraceCleaner
Classes: CampfireNotifier, EmailNotifier, HipchatNotifier, IrcNotifier, Notifier, SlackNotifier, UndefinedNotifierError, WebhookNotifier
Constant Summary
collapse
- @@logger =
Logger.new(STDOUT)
- @@ignored_exceptions =
%w{ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError ActionController::UnknownFormat}
- @@ignores =
Store conditions that decide when exceptions must be ignored or not.
[]
- @@notifiers =
Store notifiers that send notifications when exceptions are raised.
{}
Class Method Summary
collapse
Class Method Details
.clear_ignore_conditions! ⇒ Object
76
77
78
|
# File 'lib/exception_notifier.rb', line 76
def clear_ignore_conditions!
@@ignores.clear
end
|
.ignore_if(&block) ⇒ Object
Adds a condition to decide when an exception must be ignored or not.
ExceptionNotifier.ignore_if do |exception, options|
not Rails.env.production?
end
72
73
74
|
# File 'lib/exception_notifier.rb', line 72
def ignore_if(&block)
@@ignores << block
end
|
.notifiers ⇒ Object
63
64
65
|
# File 'lib/exception_notifier.rb', line 63
def notifiers
@@notifiers.keys
end
|
.notify_exception(exception, options = {}) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/exception_notifier.rb', line 34
def notify_exception(exception, options={})
return false if ignored_exception?(options[:ignore_exceptions], exception)
return false if ignored?(exception, options)
selected_notifiers = options.delete(:notifiers) || notifiers
[*selected_notifiers].each do |notifier|
fire_notification(notifier, exception, options.dup)
end
true
end
|
.register_exception_notifier(name, notifier_or_options) ⇒ Object
Also known as:
add_notifier
44
45
46
47
48
49
50
51
52
|
# File 'lib/exception_notifier.rb', line 44
def register_exception_notifier(name, notifier_or_options)
if notifier_or_options.respond_to?(:call)
@@notifiers[name] = notifier_or_options
elsif notifier_or_options.is_a?(Hash)
create_and_register_notifier(name, notifier_or_options)
else
raise ArgumentError, "Invalid notifier '#{name}' defined as #{notifier_or_options.inspect}"
end
end
|
.registered_exception_notifier(name) ⇒ Object
59
60
61
|
# File 'lib/exception_notifier.rb', line 59
def registered_exception_notifier(name)
@@notifiers[name]
end
|
.unregister_exception_notifier(name) ⇒ Object
55
56
57
|
# File 'lib/exception_notifier.rb', line 55
def unregister_exception_notifier(name)
@@notifiers.delete(name)
end
|