Module: CrashLog
- Extended by:
- Logging::ClassMethods
- Defined in:
- lib/crash_log/rails.rb,
lib/crash_log.rb,
lib/crash_log/rack.rb,
lib/crash_log/helpers.rb,
lib/crash_log/logging.rb,
lib/crash_log/payload.rb,
lib/crash_log/railtie.rb,
lib/crash_log/version.rb,
lib/crash_log/reporter.rb,
lib/crash_log/backtrace.rb,
lib/crash_log/configuration.rb,
lib/crash_log/backtrace/line.rb,
lib/crash_log/system_information.rb,
lib/crash_log/backtrace/line_cache.rb,
lib/crash_log/rails/controller_methods.rb,
lib/crash_log/rails/action_controller_rescue.rb,
lib/crash_log/rails/middleware/debug_exception_catcher.rb
Overview
Rails 3.x support
Defined Under Namespace
Modules: Helpers, Logging, Rails Classes: Backtrace, Configuration, Payload, Rack, Railtie, Reporter, SystemInformation
Constant Summary collapse
- LOG_PREFIX =
'** [CrashLog]'- VERSION =
"1.0.7"
Class Attribute Summary collapse
-
.reporter ⇒ Object
Returns the value of attribute reporter.
Class Method Summary collapse
-
.configuration ⇒ Object
The global configuration object.
-
.configure(announce = false, &block) ⇒ Object
Configure the gem to send notifications, at the very least an api_key is required.
-
.ignored?(exception) ⇒ Boolean
Looks up ignored exceptions.
-
.live? ⇒ Boolean
Is the logger live.
-
.logger ⇒ Object
The default logging device.
-
.notify(exception, data = {}) ⇒ Object
Sends a notification to CrashLog.
-
.notify_or_ignore(exception, context = {}) ⇒ Object
Sends the notice unless it is one of the default ignored exceptions.
-
.report_for_duty! ⇒ Object
Print a message at the top of the applciation’s logs to say we’re ready.
- .reset_configuration! ⇒ Object
Methods included from Logging::ClassMethods
color_for_level, colorize, colorize?, log_exception, logger, prefix
Class Attribute Details
.reporter ⇒ Object
Returns the value of attribute reporter.
24 25 26 |
# File 'lib/crash_log.rb', line 24 def reporter @reporter end |
Class Method Details
.configuration ⇒ Object
The global configuration object.
104 105 106 |
# File 'lib/crash_log.rb', line 104 def configuration @configuration ||= Configuration.new end |
.configure(announce = false, &block) ⇒ Object
Configure the gem to send notifications, at the very least an api_key is required.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/crash_log.rb', line 82 def configure(announce = false, &block) if block_given? yield(configuration) if live? self.reporter = CrashLog::Reporter.new(configuration) if configuration.valid? if announce.eql?(true) report_for_duty! else debug("Configuration updated successfully") end elsif !configuration.invalid_keys.include?(:api_key) error("Not configured correctly. Missing the following keys: #{configuration.invalid_keys.join(', ')}") end end end configuration end |
.ignored?(exception) ⇒ Boolean
Looks up ignored exceptions
Returns true if this exception should be ignored, false otherwise.
128 129 130 |
# File 'lib/crash_log.rb', line 128 def ignored?(exception) configuration.ignored?(exception) end |
.live? ⇒ Boolean
Is the logger live
Returns true if the current stage is included in the release stages config, false otherwise.
121 122 123 |
# File 'lib/crash_log.rb', line 121 def live? configuration.release_stage? end |
.logger ⇒ Object
The default logging device.
113 114 115 |
# File 'lib/crash_log.rb', line 113 def logger self.configuration.logger || Logger.new($stdout) end |
.notify(exception, data = {}) ⇒ Object
Sends a notification to CrashLog
This is the main entry point into the exception sending stack.
Examples:
def something_dangerous
raise RuntimeError, "This is too dangerous for you"
rescue => e
CrashLog.notify(e)
end
You can also include information about the current user and Crashlog
will allow you to correlate errors by affected users:
def something_dangerous
raise RuntimeError, "This is too dangerous for you"
rescue => e
CrashLog.notify(e, {context: {current_user: current_user}})
end
Returns true if successful, otherwise false
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/crash_log.rb', line 48 def notify(exception, data = {}) send_notification(exception, data).tap do |notification| if notification info "Event sent to CrashLog.io" if notification.has_key?(:location_id) info "Event URL: http://crashlog.io/locate/#{notification[:location_id]}" else error "No Event location ID returned. There may have been a problem processing this Event" end else error "Failed to send event to CrashLog.io" log_exception(exception) end end end |
.notify_or_ignore(exception, context = {}) ⇒ Object
Sends the notice unless it is one of the default ignored exceptions.
65 66 67 |
# File 'lib/crash_log.rb', line 65 def notify_or_ignore(exception, context = {}) notify(exception, context) unless ignored?(exception) end |
.report_for_duty! ⇒ Object
Print a message at the top of the applciation’s logs to say we’re ready.
70 71 72 73 74 75 76 77 78 |
# File 'lib/crash_log.rb', line 70 def report_for_duty! application = reporter.announce if application info("Configured correctly and ready to handle exceptions for '#{application}'") else error("Failed to report for duty, your application failed to authenticate correctly with stdin.crashlog.io") end end |
.reset_configuration! ⇒ Object
108 109 110 |
# File 'lib/crash_log.rb', line 108 def reset_configuration! @configuration = Configuration.new end |