Module: LighthouseExceptionLogger::Catcher

Defined in:
lib/LighthouseExceptionLogger.rb

Overview

Include this module in Controllers in which you want to be notified of errors.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



89
90
91
92
93
94
# File 'lib/LighthouseExceptionLogger.rb', line 89

def self.included(base) #:nodoc:
  if base.instance_methods.include? 'rescue_action_in_public' and !base.instance_methods.include? 'rescue_action_in_public_without_LighthouseExceptionLogger'
    base.send(:alias_method, :rescue_action_in_public_without_LighthouseExceptionLogger, :rescue_action_in_public)
    base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_LighthouseExceptionLogger)
  end
end

Instance Method Details

#loggerObject

Returns the default logger or a logger that prints to STDOUT. Necessary for manual notifications outside of controllers.



117
118
119
120
121
# File 'lib/LighthouseExceptionLogger.rb', line 117

def logger
  ActiveRecord::Base.logger
rescue
  @logger ||= Logger.new(STDERR)
end

#notify_lighthouse(hash_or_exception) ⇒ Object Also known as: inform_lighthouse

This method should be used for sending manual notifications while you are still inside the controller. Otherwise it works like HoptoadNotifier.notify.



105
106
107
108
109
110
111
# File 'lib/LighthouseExceptionLogger.rb', line 105

def notify_lighthouse hash_or_exception
  if public_environment?
    notice = normalize_notice(hash_or_exception)
    notice = clean_notice(notice)
    send_to_LighthouseExceptionLogger(:notice => notice)
  end
end

#rescue_action_in_public_with_LighthouseExceptionLogger(exception) ⇒ Object

Overrides the rescue_action method in ActionController::Base, but does not inhibit any custom processing that is defined with Rails 2’s exception helpers.



98
99
100
101
# File 'lib/LighthouseExceptionLogger.rb', line 98

def rescue_action_in_public_with_LighthouseExceptionLogger exception
  notify_lighthouse(exception) unless ignore?(exception)
  rescue_action_in_public_without_LighthouseExceptionLogger(exception)
end