lib/crash_log.rb in crashlog-0.0.2 vs lib/crash_log.rb in crashlog-1.0.0.rc1

- old
+ new

@@ -51,11 +51,19 @@ # This will try to serialize the current user by calling `as_crashlog_context` or `as_json` # otherwise it will try `to_s` # # Returns true if successful, otherwise false def notify(exception, context = {}) - send_notification(exception, context) + send_notification(exception, context).tap do |notification| + if notification + info "Event sent to CrashLog.io" + info "Event URL: http://crashlog.io/locate/#{notification[:location_id]}" if notification.has_key?(:location_id) + else + error "Failed to send event to CrashLog.io" + log_exception(exception) + end + end end # Sends the notice unless it is one of the default ignored exceptions. def notify_or_ignore(exception, context = {}) send_notification(exception, context = {}) unless ignored?(exception) @@ -64,24 +72,27 @@ # Print a message at the top of the applciation's logs to say we're ready. def report_for_duty! application = CrashLog::Reporter.new(configuration).announce if application - info("Initialized and ready to handle exceptions for #{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 # Configure the gem to send notifications, at the very least an api_key is # required. - def configure - yield(configuration) if block_given? - if configuration.valid? - report_for_duty! - else - error('Not configured correctly') + def configure(&block) + if block_given? + yield(configuration) + + if configuration.valid? + report_for_duty! + elsif !configuration.invalid_keys.include?(:api_key) + error("Not configured correctly. Missing the following keys: #{configuration.invalid_keys.join(', ')}") + end end end # The global configuration object. def configuration @@ -109,10 +120,12 @@ end private def send_notification(exception, context = {}) - build_payload(exception, context).deliver! if live? + if live? + build_payload(exception, context).deliver! + end end def build_payload(exception, context = {}) Payload.build(exception, configuration) do |payload| payload.add_context(context)