Skip to content

Instantly share code, notes, and snippets.

@stevehanson
Last active March 28, 2017 17:30
Show Gist options
  • Save stevehanson/b5369bdbfaee47257ee0 to your computer and use it in GitHub Desktop.
Save stevehanson/b5369bdbfaee47257ee0 to your computer and use it in GitHub Desktop.
Bug Tracking
class Bug
# log an error message to standard out
def self.log(message, data = {})
raise StandardError.new(message)
rescue => e
log_error(e, data)
end
# log an error/exception to standard out
def self.log_error(error, data = {})
Rails.logger.error("============================================")
Rails.logger.error("An error occurred::")
Rails.logger.error("Type: #{error.class}")
Rails.logger.error("Error: #{error.message}")
Rails.logger.error("Data: #{data}") if data.any?
Rails.logger.error("Backtrace:\n " + error.backtrace.first(5).join("\n")) if error.backtrace
Rails.logger.error("============================================")
end
# log an error message to Raygun and log to standard out
def self.track(message, data = {})
raise StandardError.new(message)
rescue => e
track_error(e, data)
end
# log an error/exception to Raygun and log to standard out
def self.track_error(error, data = {})
log_error(error, data)
Raygun.track_exception(error, custom_data: data)
end
end
begin
something_that_might_fail
rescue => e
Bug.track_error(e)
end
if thing_failed
Bug.track("This thing failed")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment