Module: HoptoadNotifier

Defined in:
lib/hoptoad_notifier.rb,
lib/hoptoad_notifier/rack.rb,
lib/hoptoad_notifier/rails.rb,
lib/hoptoad_notifier/notice.rb,
lib/hoptoad_notifier/sender.rb,
lib/hoptoad_notifier/railtie.rb,
lib/hoptoad_notifier/version.rb,
lib/hoptoad_notifier/backtrace.rb,
lib/hoptoad_notifier/configuration.rb,
lib/hoptoad_notifier/user_informer.rb,
lib/hoptoad_notifier/rails/error_lookup.rb,
lib/hoptoad_notifier/rails/controller_methods.rb,
lib/hoptoad_notifier/rails/javascript_notifier.rb,
lib/hoptoad_notifier/rails/action_controller_catcher.rb

Overview

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

Defined Under Namespace

Modules: Rails Classes: Backtrace, Configuration, Notice, Rack, Railtie, Sender, UserInformer

Constant Summary collapse

API_VERSION =
"2.0"
LOG_PREFIX =
"** [Hoptoad] "
HEADERS =
{
  'Content-type'             => 'text/xml',
  'Accept'                   => 'text/xml, application/xml'
}
VERSION =
"2.4.8".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

A Hoptoad configuration object. Must act like a hash and return sensible values for all Hoptoad configuration options. See HoptoadNotifier::Configuration.



37
38
39
# File 'lib/hoptoad_notifier.rb', line 37

def configuration
  @configuration
end

.senderObject

The sender object is responsible for delivering formatted data to the Hoptoad server. Must respond to #send_to_hoptoad. See HoptoadNotifier::Sender.



33
34
35
# File 'lib/hoptoad_notifier.rb', line 33

def sender
  @sender
end

Class Method Details

.build_lookup_hash_for(exception, options = {}) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/hoptoad_notifier.rb', line 107

def build_lookup_hash_for(exception, options = {})
  notice = build_notice_for(exception, options)

  result = {}
  result[:action]           = notice.action      rescue nil
  result[:component]        = notice.component   rescue nil
  result[:error_class]      = notice.error_class if notice.error_class
  result[:environment_name] = 'production'

  unless notice.backtrace.lines.empty?
    result[:file]        = notice.backtrace.lines.first.file
    result[:line_number] = notice.backtrace.lines.first.number
  end

  result
end

.configure(silent = false) {|configuration| ... } ⇒ Object

Call this method to modify defaults in your initializers.

Examples:

HoptoadNotifier.configure do |config|
  config.api_key = '1234567890abcdef'
  config.secure  = false
end

Yields:



78
79
80
81
82
83
# File 'lib/hoptoad_notifier.rb', line 78

def configure(silent = false)
  self.configuration ||= Configuration.new
  yield(configuration)
  self.sender = Sender.new(configuration)
  report_ready unless silent
end

.environment_infoObject

Returns the Ruby version, Rails version, and current Rails environment



55
56
57
58
59
# File 'lib/hoptoad_notifier.rb', line 55

def environment_info
  info = "[Ruby: #{RUBY_VERSION}]"
  info << " [#{configuration.framework}]"
  info << " [Env: #{configuration.environment_name}]"
end

.loggerObject

Look for the Rails logger currently defined



67
68
69
# File 'lib/hoptoad_notifier.rb', line 67

def logger
  self.configuration.logger
end

.notify(exception, opts = {}) ⇒ Object

Sends an exception manually using this method, even when you are not in a controller.

Parameters:

  • exception (Exception)

    The exception you want to notify Hoptoad about.

  • opts (Hash) (defaults to: {})

    Data that will be sent to Hoptoad.

Options Hash (opts):

  • :api_key (String)

    The API key for this project. The API key is a unique identifier that Hoptoad uses for identification.

  • :error_message (String)

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

  • :backtrace (String)

    A backtrace, usually obtained with caller.

  • :request (String)

    The controller’s request object.

  • :session (String)

    The contents of the user’s session.

  • :environment (String)

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



96
97
98
# File 'lib/hoptoad_notifier.rb', line 96

def notify(exception, opts = {})
  send_notice(build_notice_for(exception, opts))
end

.notify_or_ignore(exception, opts = {}) ⇒ Object

Sends the notice unless it is one of the default ignored exceptions

See Also:



102
103
104
105
# File 'lib/hoptoad_notifier.rb', line 102

def notify_or_ignore(exception, opts = {})
  notice = build_notice_for(exception, opts)
  send_notice(notice) unless notice.ignore?
end

.report_environment_infoObject

Prints out the environment info to the log for debugging help



45
46
47
# File 'lib/hoptoad_notifier.rb', line 45

def report_environment_info
  write_verbose_log("Environment Info: #{environment_info}")
end

.report_readyObject

Tell the log that the Notifier is good to go



40
41
42
# File 'lib/hoptoad_notifier.rb', line 40

def report_ready
  write_verbose_log("Notifier #{VERSION} ready to catch errors")
end

.report_response_body(response) ⇒ Object

Prints out the response body from Hoptoad for debugging help



50
51
52
# File 'lib/hoptoad_notifier.rb', line 50

def report_response_body(response)
  write_verbose_log("Response from Hoptoad: \n#{response}")
end

.write_verbose_log(message) ⇒ Object

Writes out the given message to the #logger



62
63
64
# File 'lib/hoptoad_notifier.rb', line 62

def write_verbose_log(message)
  logger.info LOG_PREFIX + message if logger
end