Module: LighthouseExceptionLogger

Defined in:
lib/LighthouseExceptionLogger.rb

Overview

Plugin for applications to automatically post errors to the Hoptoad of their choice.

Defined Under Namespace

Modules: Catcher Classes: Sender

Constant Summary collapse

VERSION =
'0.1'
IGNORE_DEFAULT =
['ActiveRecord::RecordNotFound',
'ActionController::RoutingError',
'ActionController::InvalidAuthenticityToken',
'CGI::Session::CookieStore::TamperedWithCookie']

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



21
22
23
# File 'lib/LighthouseExceptionLogger.rb', line 21

def api_key
  @api_key
end

.backtrace_filtersObject (readonly)

Returns the value of attribute backtrace_filters.



22
23
24
# File 'lib/LighthouseExceptionLogger.rb', line 22

def backtrace_filters
  @backtrace_filters
end

.hostObject

Returns the value of attribute host.



21
22
23
# File 'lib/LighthouseExceptionLogger.rb', line 21

def host
  @host
end

.portObject

Returns the value of attribute port.



21
22
23
# File 'lib/LighthouseExceptionLogger.rb', line 21

def port
  @port
end

.secureObject

Returns the value of attribute secure.



21
22
23
# File 'lib/LighthouseExceptionLogger.rb', line 21

def secure
  @secure
end

Class Method Details

.environment_filtersObject



51
52
53
# File 'lib/LighthouseExceptionLogger.rb', line 51

def environment_filters
  @environment_filters ||= %w()
end

.filter_backtrace(&block) ⇒ Object

Takes a block and adds it to the list of backtrace filters. When the filters run, the block will be handed each line of the backtrace and can modify it as necessary. For example, by default a path matching the RAILS_ROOT constant will be transformed into “[RAILS_ROOT]”



28
29
30
# File 'lib/LighthouseExceptionLogger.rb', line 28

def filter_backtrace &block
  (@backtrace_filters ||= []) << block
end

.ignoreObject

Returns the list of errors that are being ignored. The array can be appended to.



33
34
35
36
37
# File 'lib/LighthouseExceptionLogger.rb', line 33

def ignore
  @ignore ||= (LighthouseExceptionLogger::IGNORE_DEFAULT.dup)
  @ignore.flatten!
  @ignore
end

.ignore_only=(names) ⇒ Object

Sets the list of ignored errors to only what is passed in here. This method can be passed a single error or a list of errors.



41
42
43
# File 'lib/LighthouseExceptionLogger.rb', line 41

def ignore_only=(names)
  @ignore = [names].flatten
end

.notify(notice = {}) ⇒ Object

You can send an exception manually using this method, even when you are not in a controller. You can pass an exception or a hash that contains the attributes that would be sent to Hoptoad:

  • api_key: The API key for this project. The API key is a unique identifier that Hoptoad

uses for identification.

  • error_message: The error returned by the exception (or the message you want to log).

  • backtrace: A backtrace, usually obtained with caller.

  • request: The controller’s request object.

  • session: The contents of the user’s session.

  • environment: ENV merged with the contents of the request’s environment.



65
66
67
# File 'lib/LighthouseExceptionLogger.rb', line 65

def notify notice = {}
  Sender.new.notify_lighthouse( notice )
end

.params_filtersObject

Returns a list of parameters that should be filtered out of what is sent to Lighthouse. By default, all “password” attributes will have their contents replaced.



47
48
49
# File 'lib/LighthouseExceptionLogger.rb', line 47

def params_filters
  @params_filters ||= %w(password)
end