module Batbugger

Constants

HEADERS
LOG_PREFIX
VERSION

Attributes

configuration[W]
sender[RW]

Public Class Methods

build_lookup_hash_for(exception, options = {}) click to toggle source
# File lib/batbugger.rb, line 73
def build_lookup_hash_for(exception, options = {})
  notice = build_notice_for(exception, options)

  result = {}
  result[:action]           = notice.action      rescue nil
  result[:component]        = notice.component   rescue nil
  result[:error_class]      = notice.error_class if notice.error_class
  result[:environment_name] = 'production'

  unless notice.backtrace.lines.empty?
    result[:file]        = notice.backtrace.lines[0].file
    result[:line_number] = notice.backtrace.lines[0].number
  end

  result
end
clear!() click to toggle source
# File lib/batbugger.rb, line 96
def clear!
  Thread.current[:batbugger_context] = nil
end
configuration() click to toggle source
# File lib/batbugger.rb, line 60
def configuration
  @configuration ||= Configuration.new
end
configure(silent = false) { |configuration| ... } click to toggle source
# File lib/batbugger.rb, line 53
def configure(silent = false)
  yield(configuration)
  self.sender = Sender.new(configuration)
  report_ready unless silent
  self.sender
end
context(hash = {}) click to toggle source
# File lib/batbugger.rb, line 90
def context(hash = {})
  Thread.current[:batbugger_context] ||= {}
  Thread.current[:batbugger_context].merge!(hash)
  self
end
environment_info() click to toggle source
# File lib/batbugger.rb, line 39
def environment_info
  info = "[Ruby: #{RUBY_VERSION}]"
  info << " [#{configuration.framework}]" if configuration.framework
  info << " [Env: #{configuration.environment_name}]" if configuration.environment_name
end
logger() click to toggle source
# File lib/batbugger.rb, line 49
def logger
  self.configuration.logger
end
notify(exception, options = {}) click to toggle source
# File lib/batbugger.rb, line 64
def notify(exception, options = {})
  send_notice(build_notice_for(exception, options))
end
notify_or_ignore(exception, opts = {}) click to toggle source
# File lib/batbugger.rb, line 68
def notify_or_ignore(exception, opts = {})
  notice = build_notice_for(exception, opts)
  send_notice(notice) unless notice.ignore?
end
report_environment_info() click to toggle source
# File lib/batbugger.rb, line 31
def report_environment_info
  write_verbose_log("Environment Info: #{environment_info}")
end
report_ready() click to toggle source
# File lib/batbugger.rb, line 27
def report_ready
  write_verbose_log("Notifier #{VERSION} ready to catch errors", :info)
end
report_response_body(response) click to toggle source
# File lib/batbugger.rb, line 35
def report_response_body(response)
  write_verbose_log("Response from Batbugger: \n#{response}")
end
write_verbose_log(message, level = Batbugger.configuration.debug ? :info : :debug) click to toggle source
# File lib/batbugger.rb, line 45
def write_verbose_log(message, level = Batbugger.configuration.debug ? :info : :debug)
  logger.send(level, LOG_PREFIX + message) if logger
end

Private Class Methods

build_notice_for(exception, opts = {}) click to toggle source
# File lib/batbugger.rb, line 112
def build_notice_for(exception, opts = {})
  exception = unwrap_exception(exception)
  opts = opts.merge(:exception => exception) if exception.is_a?(Exception)
  opts = opts.merge(exception.to_hash) if exception.respond_to?(:to_hash)
  Notice.new(configuration.merge(opts))
end
send_notice(notice) click to toggle source
# File lib/batbugger.rb, line 102
def send_notice(notice)
  if configuration.public?
    if configuration.async?
      configuration.async.call(notice)
    else
      notice.deliver
    end
  end
end
unwrap_exception(exception) click to toggle source
# File lib/batbugger.rb, line 119
def unwrap_exception(exception)
  if exception.respond_to?(:original_exception)
    exception.original_exception
  elsif exception.respond_to?(:continued_exception)
    exception.continued_exception
  else
    exception
  end
end