Module: HoptoadNotifier
- Defined in:
- lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.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
- IGNORE_DEFAULT =
['ActiveRecord::RecordNotFound', 'ActionController::RoutingError', 'ActionController::InvalidAuthenticityToken', 'CGI::Session::CookieStore::TamperedWithCookie', 'ActionController::UnknownAction']
- IGNORE_USER_AGENT_DEFAULT =
[]
- VERSION =
"1.2.4"
- LOG_PREFIX =
"** [Hoptoad] "
- HEADERS =
{ 'Content-type' => 'application/x-yaml', 'Accept' => 'text/xml, application/xml', 'X-Hoptoad-Client-Name' => 'Hoptoad Notifier', 'X-Hoptoad-Client-Version' => VERSION }
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.host ⇒ Object
The host to connect to.
-
.http_open_timeout ⇒ Object
The HTTP open timeout (defaults to 2 seconds).
-
.http_read_timeout ⇒ Object
The HTTP read timeout (defaults to 5 seconds).
-
.output ⇒ Object
Returns the value of attribute output.
-
.port ⇒ Object
The port on which your Hoptoad server runs.
-
.proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
.proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
-
.proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
.proxy_user ⇒ Object
Returns the value of attribute proxy_user.
-
.secure ⇒ Object
Returns the value of attribute secure.
Class Method Summary collapse
- .add_default_filters ⇒ Object
- .backtrace_filters ⇒ Object
-
.configure {|_self| ... } ⇒ Object
Call this method to modify defaults in your initializers.
-
.default_notice_options ⇒ Object
:nodoc:.
- .environment_filters ⇒ Object
- .environment_info ⇒ Object
-
.filter_backtrace(&block) ⇒ Object
Takes a block and adds it to the list of backtrace filters.
-
.ignore ⇒ Object
Returns the list of errors that are being ignored.
-
.ignore_by_filter(&block) ⇒ Object
Takes a block and adds it to the list of ignore filters.
- .ignore_by_filters ⇒ Object
-
.ignore_only=(names) ⇒ Object
Sets the list of ignored errors to only what is passed in here.
-
.ignore_user_agent ⇒ Object
Returns the list of user agents that are being ignored.
-
.ignore_user_agent_only=(names) ⇒ Object
Sets the list of ignored user agents to only what is passed in here.
-
.logger ⇒ Object
Checking for the logger in hopes we can get rid of the ugly syntax someday.
-
.notify(notice = {}) ⇒ Object
You can send an exception manually using this method, even when you are not in a controller.
-
.params_filters ⇒ Object
Returns a list of parameters that should be filtered out of what is sent to Hoptoad.
-
.protocol ⇒ Object
:nodoc:.
- .report_environment_info ⇒ Object
- .report_ready ⇒ Object
- .report_response_body(response) ⇒ Object
-
.url ⇒ Object
:nodoc:.
- .write_verbose_log(message) ⇒ Object
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
32 33 34 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 32 def api_key @api_key end |
.host ⇒ Object
The host to connect to.
65 66 67 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 65 def host @host end |
.http_open_timeout ⇒ Object
The HTTP open timeout (defaults to 2 seconds).
70 71 72 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 70 def http_open_timeout @http_open_timeout end |
.http_read_timeout ⇒ Object
The HTTP read timeout (defaults to 5 seconds).
75 76 77 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 75 def http_read_timeout @http_read_timeout end |
.output ⇒ Object
Returns the value of attribute output.
32 33 34 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 32 def output @output end |
.port ⇒ Object
The port on which your Hoptoad server runs.
60 61 62 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 60 def port @port end |
.proxy_host ⇒ Object
Returns the value of attribute proxy_host.
32 33 34 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 32 def proxy_host @proxy_host end |
.proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
32 33 34 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 32 def proxy_pass @proxy_pass end |
.proxy_port ⇒ Object
Returns the value of attribute proxy_port.
32 33 34 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 32 def proxy_port @proxy_port end |
.proxy_user ⇒ Object
Returns the value of attribute proxy_user.
32 33 34 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 32 def proxy_user @proxy_user end |
.secure ⇒ Object
Returns the value of attribute secure.
32 33 34 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 32 def secure @secure end |
Class Method Details
.add_default_filters ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 195 def add_default_filters self.backtrace_filters.clear filter_backtrace do |line| line.gsub(/#{RAILS_ROOT}/, "[RAILS_ROOT]") end filter_backtrace do |line| line.gsub(/^\.\//, "") end filter_backtrace do |line| if defined?(Gem) Gem.path.inject(line) do |line, path| line.gsub(/#{path}/, "[GEM_ROOT]") end end end filter_backtrace do |line| line if line !~ /lib\/#{File.basename(__FILE__)}/ end end |
.backtrace_filters ⇒ Object
35 36 37 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 35 def backtrace_filters @backtrace_filters ||= [] end |
.configure {|_self| ... } ⇒ Object
Call this method to modify defaults in your initializers.
HoptoadNotifier.configure do |config|
config.api_key = '1234567890abcdef'
config.secure = false
end
NOTE: secure connections are not yet supported.
153 154 155 156 157 158 159 160 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 153 def configure add_default_filters yield self if defined?(ActionController::Base) && !ActionController::Base.include?(HoptoadNotifier::Catcher) ActionController::Base.send(:include, HoptoadNotifier::Catcher) end report_ready end |
.default_notice_options ⇒ Object
:nodoc:
170 171 172 173 174 175 176 177 178 179 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 170 def #:nodoc: { :api_key => HoptoadNotifier.api_key, :error_message => 'Notification', :backtrace => caller, :request => {}, :session => {}, :environment => ENV.to_hash } end |
.environment_filters ⇒ Object
111 112 113 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 111 def environment_filters @environment_filters ||= %w() end |
.environment_info ⇒ Object
127 128 129 130 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 127 def environment_info info = "[Ruby: #{RUBY_VERSION}]" info << " [Rails: #{::Rails::VERSION::STRING}] [RailsEnv: #{RAILS_ENV}]" if defined?(Rails) 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]”
55 56 57 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 55 def filter_backtrace &block self.backtrace_filters << block end |
.ignore ⇒ Object
Returns the list of errors that are being ignored. The array can be appended to.
80 81 82 83 84 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 80 def ignore @ignore ||= (HoptoadNotifier::IGNORE_DEFAULT.dup) @ignore.flatten! @ignore end |
.ignore_by_filter(&block) ⇒ Object
Takes a block and adds it to the list of ignore filters. When the filters run, the block will be handed the exception. If the block yields a value equivalent to “true,” the exception will be ignored, otherwise it will be processed by hoptoad.
47 48 49 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 47 def ignore_by_filter &block self.ignore_by_filters << block end |
.ignore_by_filters ⇒ Object
39 40 41 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 39 def ignore_by_filters @ignore_by_filters ||= [] 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.
88 89 90 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 88 def ignore_only=(names) @ignore = [names].flatten end |
.ignore_user_agent ⇒ Object
Returns the list of user agents that are being ignored. The array can be appended to.
93 94 95 96 97 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 93 def ignore_user_agent @ignore_user_agent ||= (HoptoadNotifier::IGNORE_USER_AGENT_DEFAULT.dup) @ignore_user_agent.flatten! @ignore_user_agent end |
.ignore_user_agent_only=(names) ⇒ Object
Sets the list of ignored user agents to only what is passed in here. This method can be passed a single user agent or a list of user agents.
101 102 103 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 101 def ignore_user_agent_only=(names) @ignore_user_agent = [names].flatten end |
.logger ⇒ Object
Checking for the logger in hopes we can get rid of the ugly syntax someday
137 138 139 140 141 142 143 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 137 def logger if defined?(Rails.logger) Rails.logger elsif defined?(RAILS_DEFAULT_LOGGER) RAILS_DEFAULT_LOGGER end 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.
191 192 193 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 191 def notify notice = {} Sender.new.notify_hoptoad( notice ) end |
.params_filters ⇒ Object
Returns a list of parameters that should be filtered out of what is sent to Hoptoad. By default, all “password” attributes will have their contents replaced.
107 108 109 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 107 def params_filters @params_filters ||= %w(password password_confirmation) end |
.protocol ⇒ Object
:nodoc:
162 163 164 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 162 def protocol #:nodoc: secure ? "https" : "http" end |
.report_environment_info ⇒ Object
119 120 121 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 119 def report_environment_info write_verbose_log("Environment Info: #{environment_info}") end |
.report_ready ⇒ Object
115 116 117 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 115 def report_ready write_verbose_log("Notifier #{VERSION} ready to catch errors") end |
.report_response_body(response) ⇒ Object
123 124 125 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 123 def report_response_body(response) write_verbose_log("Response from Hoptoad: \n#{response}") end |
.url ⇒ Object
:nodoc:
166 167 168 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 166 def url #:nodoc: URI.parse("#{protocol}://#{host}:#{port}/notices/") end |
.write_verbose_log(message) ⇒ Object
132 133 134 |
# File 'lib/vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb', line 132 def write_verbose_log() logger.info LOG_PREFIX + if logger end |