Class: ExceptionNotifier::DatabaseNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notifier/database_notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(_options) ⇒ DatabaseNotifier

Returns a new instance of DatabaseNotifier.


4
5
6
# File 'lib/exception_notifier/database_notifier.rb', line 4

def initialize(_options)
  # do something with the options...
end

Instance Method Details

#call(exception, _options = {}) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/exception_notifier/database_notifier.rb', line 8

def call(exception, _options = {})
  # send the notification
  @title = exception.message
  messages = []
  messages << exception.inspect
  unless exception.backtrace.blank?
    messages << "\n"
    messages << exception.backtrace
  end

  if Rails.env.production?
    ExceptionLog.create(title: @title, body: messages.join("\n"))
  else
    Rails.logger.info "\n======================"
    Rails.logger.info messages.join("\n")
    Rails.logger.info "======================\n"
  end
end