Class: Harbor::ExceptionNotifier
- Inherits:
-
Object
- Object
- Harbor::ExceptionNotifier
- Defined in:
- lib/harbor/exception_notifier.rb
Overview
Utility class for receiving email notifications of exceptions in non-development environments.
services.register("mailer", Harbor::Mailer)
services.register("mail_server", Harbor::SendmailServer)
require 'harbor/exception_notifier'
You will then receive email alerts for all 500 errors in the format of:
From: errors@request_host
Subject: [ERROR] [request_host] [environment] Exception description
Body: stack trace found in log, with request details.
Class Method Summary collapse
- .notification_address ⇒ Object
- .notification_address=(address) ⇒ Object
- .notification_address? ⇒ Boolean
- .notify(exception, request, response, trace) ⇒ Object
Class Method Details
.notification_address ⇒ Object
23 24 25 26 27 |
# File 'lib/harbor/exception_notifier.rb', line 23 def self.notification_address @@notification_address rescue NameError raise "Harbor::ExceptionMailer.notification_address not set." end |
.notification_address=(address) ⇒ Object
19 20 21 |
# File 'lib/harbor/exception_notifier.rb', line 19 def self.notification_address=(address) @@notification_address = address end |
.notification_address? ⇒ Boolean
29 30 31 |
# File 'lib/harbor/exception_notifier.rb', line 29 def self.notification_address? defined?(@@notification_address) end |
.notify(exception, request, response, trace) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/harbor/exception_notifier.rb', line 33 def self.notify(exception, request, response, trace) return if request.environment == "development" mailer = request.application.services.get("mailer") mailer.to = notification_address host = request.env["HTTP_X_FORWARDED_HOST"] || request.host mailer.from = "errors@#{host}" subject = exception.to_s # We can't have multi-line subjects, so we chop off extra lines if subject[$/] subject = subject.split($/, 2)[0] + "..." end mailer.subject = "[ERROR] [#{request.host}] [#{request.environment}] #{subject}" mailer.text = trace mailer.set_header("X-Priority", 1) mailer.set_header("X-MSMail-Priority", "High") mailer.send! end |