Class: ErrorStalker::Client
- Inherits:
-
Object
- Object
- ErrorStalker::Client
- Defined in:
- lib/error_stalker/client.rb
Overview
The error_stalker client enables you to log exception data to a backend. The class method ErrorStalker::Client.report is usually the method you want to use out of this class, although for those who like block syntax, this class also provides a report_exceptions
method that reports all exceptions raised inside a block.
Class Method Summary collapse
-
.backend=(new_backend) ⇒ Object
Sets the backend the client will use to report exceptions to
new_backend
, an ErrorStalker::Backend instance. -
.report(application_name, exception, extra_data = {}) ⇒ Object
Report an exception to the exception logging backend.
-
.report_exceptions(application_name, options = {}) ⇒ Object
Calls
report
on all exceptions raised in the provided block of code.
Class Method Details
.backend=(new_backend) ⇒ Object
Sets the backend the client will use to report exceptions to new_backend
, an ErrorStalker::Backend instance. By default, exceptions are logged using ErrorStalker::Backend::LogFileBackend.
15 16 17 |
# File 'lib/error_stalker/client.rb', line 15 def self.backend=(new_backend) @backend = new_backend end |
.report(application_name, exception, extra_data = {}) ⇒ Object
Report an exception to the exception logging backend.
-
application_name: A tag representing the name of the app that this exception occurred in. This is used for advanced filtering on the server, if the server backend is used.
-
exception: The exception object that was thrown. This can also be a string, but you won’t get information like the backtrace if you don’t pass an actual exception subclass.
-
extra_data: A hash of additional data to log with the exception. Depending on which backend the server uses, this may or may not be indexable.
32 33 34 35 36 37 |
# File 'lib/error_stalker/client.rb', line 32 def self.report(application_name, exception, extra_data = {}) begin @backend.report(ErrorStalker::ExceptionReport.new(:application => application_name, :exception => exception, :data => extra_data)) rescue Exception => e # keep going if this fails end end |
.report_exceptions(application_name, options = {}) ⇒ Object
Calls report
on all exceptions raised in the provided block of code. options
can be:
- :reraise
-
if true, reraise exceptions caught in this block. Defaults to true.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/error_stalker/client.rb', line 44 def self.report_exceptions(application_name, = {}) = {:reraise => true}.merge() begin yield rescue => e report(application_name, e) if [:reraise] raise e end end end |