lib/crash_log.rb in crashlog-1.0.3 vs lib/crash_log.rb in crashlog-1.0.4

- old
+ new

@@ -1,33 +1,25 @@ -$: << File.expand_path('..', __FILE__) - -require 'crash_log/version' - -begin - require 'active_support' - require 'active_support/core_ext' -rescue LoadError - require 'activesupport' - require 'activesupport/core_ext' -end - require 'faraday' require 'multi_json' +require 'time' -require 'crash_log/railtie' if defined?(Rails::Railtie) -require 'crash_log/logging' +require File.expand_path('../core_ext/kernel/require_relative', __FILE__) +require_relative 'core_ext/hash/keys' +require_relative 'crash_log/version' +require_relative 'crash_log/logging' +require_relative 'crash_log/helpers' +require_relative 'crash_log/backtrace' +require_relative 'crash_log/configuration' +require_relative 'crash_log/payload' +require_relative 'crash_log/reporter' +require_relative 'crash_log/system_information' +require_relative 'crash_log/rack' + module CrashLog extend Logging::ClassMethods - autoload :Backtrace, 'crash_log/backtrace' - autoload :Configuration, 'crash_log/configuration' - autoload :Payload, 'crash_log/payload' - autoload :Rack, 'crash_log/rack' - autoload :Reporter, 'crash_log/reporter' - autoload :SystemInformation, 'crash_log/system_information' - LOG_PREFIX = '** [CrashLog]' class << self attr_accessor :reporter @@ -47,29 +39,33 @@ # 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, {current_user: current_user}) + # CrashLog.notify(e, {context: {current_user: current_user}}) # end # # Returns true if successful, otherwise false def notify(exception, data = {}) send_notification(exception, data).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) + 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 # Sends the notice unless it is one of the default ignored exceptions. def notify_or_ignore(exception, context = {}) - notify(exception, context = {}) unless ignored?(exception) + notify(exception, context) unless ignored?(exception) end # Print a message at the top of the applciation's logs to say we're ready. def report_for_duty! self.reporter = CrashLog::Reporter.new(configuration) @@ -92,11 +88,11 @@ if configuration.valid? if announce.eql?(true) report_for_duty! else - info("Configuration updated") + 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 @@ -106,10 +102,14 @@ # The global configuration object. def configuration @configuration ||= Configuration.new end + def reset_configuration! + @configuration = Configuration.new + end + # The default logging device. def logger self.configuration.logger || Logger.new($stdout) end @@ -129,13 +129,11 @@ end private def send_notification(exception, context = {}) - if live? - build_payload(exception, context).deliver! - end + build_payload(exception, context).deliver! if live? end def build_payload(exception, data = {}) Payload.build(exception, configuration) do |payload| if context = data.delete(:context) @@ -144,5 +142,10 @@ payload.add_data(data) end end end end + +# Require this last to resolve an issue with Rails apps that use Bundler.setup +# instead of Bundler.require which results in the CrashLog module not being made +# available in time. FIXES: https://github.com/crashlog/crashlog/issues/7 +require_relative 'crash_log/railtie' if defined?(Rails::Railtie)