Permalink
Browse files

bugsnag notification added

  • Loading branch information...
1 parent f743884 commit f31d4f2b618249c2bd74e6b5bfac654eee2779ce @tompesman committed Sep 18, 2012
Showing with 14 additions and 12 deletions.
  1. +1 −1 README.md
  2. +3 −3 bin/push
  3. +1 −1 lib/push/daemon.rb
  4. +1 −1 lib/push/daemon/database_reconnectable.rb
  5. +8 −6 lib/push/daemon/logger.rb
View
@@ -89,7 +89,7 @@ Where `<environment>` is your Rails environment and `<options>` can be:
-f, --foreground Run in the foreground. Log is not written.
-p, --pid-file PATH Path to write PID file. Relative to Rails root unless absolute.
-P, --push-poll N Frequency in seconds to check for new notifications. Default: 2.
- -n, --airbrake-notify Enables error notifications via Airbrake.
+ -n, --error-notification Enables error notifications via Airbrake or Bugsnag.
-F, --feedback-poll N Frequency in seconds to check for feedback for the feedback processor. Default: 60. Use 0 to disable.
-b, --feedback-processor PATH Path to the feedback processor. Default: lib/push/feedback_processor.
-v, --version Print this version of push.
View
@@ -5,10 +5,10 @@ require 'push'
environment = ARGV[0]
-config = Struct.new(:foreground, :pid_file, :push_poll, :airbrake_notify, :feedback_poll, :feedback_processor).new
+config = Struct.new(:foreground, :pid_file, :push_poll, :error_notification, :feedback_poll, :feedback_processor).new
config.foreground = false
config.push_poll = 2
-config.airbrake_notify = false
+config.error_notification = false
config.feedback_poll = 60
config.feedback_processor = 'lib/push/feedback_processor'
@@ -18,7 +18,7 @@ ARGV.options do |opts|
opts.on('-f', '--foreground', 'Run in the foreground. Log is not written.') { config.foreground = true }
opts.on('-p PATH', '--pid-file PATH', String, 'Path to write PID file. Relative to Rails root unless absolute.') { |path| config.pid_file = path }
opts.on('-P N', '--push-poll N', Integer, "Frequency in seconds to check for new notifications. Default: #{config.push_poll}.") { |n| config.push_poll = n }
- opts.on('-n', '--airbrake-notify', 'Enables error notifications via Airbrake.') { config.check_for_errors = true }
+ opts.on('-n', '--error-notification', 'Enables error notifications via Airbrake or Bugsnag.') { config.error_notification = true }
opts.on('-F N', '--feedback-poll N', Integer, "Frequency in seconds to check for feedback for the feedback processor. Default: #{config.feedback_poll}. Use 0 to disable.") { |n| config.feedback_poll = n }
opts.on('-b PATH', '--feedback-processor PATH', String, "Path to the feedback processor. Default: #{config.feedback_processor}.") { |n| config.feedback_processor = n }
opts.on('-v', '--version', 'Print this version of push.') { puts "push #{Push::VERSION}"; exit }
View
@@ -21,7 +21,7 @@ class << self
def self.start(config)
self.config = config
- self.logger = Logger.new(:foreground => config.foreground, :airbrake_notify => config.airbrake_notify)
+ self.logger = Logger.new(:foreground => config.foreground, :error_notification => config.error_notification)
setup_signal_hooks
daemonize unless config.foreground
write_pid_file
@@ -28,7 +28,7 @@ def database_connection_lost(name)
check_database_is_connected
break
rescue *adaptor_errors => e
- Push::Daemon.logger.error(e, :airbrake_notify => false)
+ Push::Daemon.logger.error(e, :error_notification => false)
sleep_to_avoid_thrashing
end
end
View
@@ -11,7 +11,7 @@ def info(msg)
end
def error(msg, options = {})
- airbrake_notify(msg) if notify_via_airbrake?(msg, options)
+ error_notification(msg, options)
log(:error, msg, 'ERROR')
end
@@ -23,7 +23,7 @@ def warn(msg)
def log(where, msg, prefix = nil)
if msg.is_a?(Exception)
- msg = "#{msg.class.name}, #{msg.message}: #{msg.backtrace.join("\n")}"
+ msg = "#{msg.class.name}, #{msg.message}: #{msg.backtrace.join("\n") if msg.backtrace}"
end
formatted_msg = "[#{Time.now.to_s(:db)}] "
@@ -44,18 +44,20 @@ def open_log
@logger.auto_flushing = Rails.logger.respond_to?(:auto_flushing) ? Rails.logger.auto_flushing : true
end
- def airbrake_notify(e)
- return unless @options[:airbrake_notify] == true
+ def error_notification(e, options)
+ return unless do_error_notification?(e, options)
if defined?(Airbrake)
Airbrake.notify_or_ignore(e)
elsif defined?(HoptoadNotifier)
HoptoadNotifier.notify_or_ignore(e)
+ elsif defined?(Bugsnag)
+ Bugsnag.notify(e)
end
end
- def notify_via_airbrake?(msg, options)
- msg.is_a?(Exception) && options[:airbrake_notify] != false
+ def do_error_notification?(msg, options)
+ @options[:error_notification] and options[:error_notification] != false and msg.is_a?(Exception)
end
end
end

0 comments on commit f31d4f2

Please sign in to comment.