Module: Batbugger

Defined in:
lib/batbugger.rb,
lib/batbugger/rack.rb,
lib/batbugger/notice.rb,
lib/batbugger/sender.rb,
lib/batbugger/railtie.rb,
lib/batbugger/version.rb,
lib/batbugger/backtrace.rb,
lib/batbugger/configuration.rb,
lib/batbugger/rails/controller_methods.rb,
lib/batbugger/rails/middleware/exceptions_catcher.rb

Defined Under Namespace

Modules: Rails Classes: Backtrace, Configuration, Notice, Rack, Railtie, Sender

Constant Summary collapse

VERSION =
"1.2.1"
LOG_PREFIX =
"** [Batbugger] "
HEADERS =
{
  'Content-type'             => 'application/json',
  'Accept'                   => 'text/json, application/json'
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



60
61
62
# File 'lib/batbugger.rb', line 60

def configuration
  @configuration ||= Configuration.new
end

.senderObject

Returns the value of attribute sender.



24
25
26
# File 'lib/batbugger.rb', line 24

def sender
  @sender
end

Class Method Details

.build_lookup_hash_for(exception, options = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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!Object



96
97
98
# File 'lib/batbugger.rb', line 96

def clear!
  Thread.current[:batbugger_context] = nil
end

.configure(silent = false) {|configuration| ... } ⇒ Object

Yields:



53
54
55
56
57
58
# 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 = {}) ⇒ Object



90
91
92
93
94
# File 'lib/batbugger.rb', line 90

def context(hash = {})
  Thread.current[:batbugger_context] ||= {}
  Thread.current[:batbugger_context].merge!(hash)
  self
end

.environment_infoObject



39
40
41
42
43
# 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

.loggerObject



49
50
51
# File 'lib/batbugger.rb', line 49

def logger
  self.configuration.logger
end

.notify(exception, options = {}) ⇒ Object



64
65
66
# File 'lib/batbugger.rb', line 64

def notify(exception, options = {})
  send_notice(build_notice_for(exception, options))
end

.notify_or_ignore(exception, opts = {}) ⇒ Object



68
69
70
71
# 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_infoObject



31
32
33
# File 'lib/batbugger.rb', line 31

def report_environment_info
  write_verbose_log("Environment Info: #{environment_info}")
end

.report_readyObject



27
28
29
# File 'lib/batbugger.rb', line 27

def report_ready
  write_verbose_log("Notifier #{VERSION} ready to catch errors", :info)
end

.report_response_body(response) ⇒ Object



35
36
37
# 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) ⇒ Object



45
46
47
# 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