exception_notification 2.6.1 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +12 -0
- data/CONTRIBUTING.md +33 -0
- data/Gemfile.lock +61 -33
- data/README.md +59 -12
- data/exception_notification.gemspec +5 -3
- data/lib/exception_notifier.rb +7 -0
- data/lib/exception_notifier/campfire_notifier.rb +30 -0
- data/lib/exception_notifier/notifier.rb +55 -26
- data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +1 -0
- data/lib/exception_notifier/views/exception_notifier/_data.html.erb +1 -0
- data/lib/exception_notifier/views/exception_notifier/_environment.html.erb +8 -0
- data/lib/exception_notifier/views/exception_notifier/_request.html.erb +5 -0
- data/lib/exception_notifier/views/exception_notifier/_session.html.erb +2 -0
- data/lib/exception_notifier/views/exception_notifier/_title.html.erb +3 -0
- data/lib/exception_notifier/views/exception_notifier/background_exception_notification.html.erb +26 -0
- data/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb +5 -3
- data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +36 -0
- data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +4 -3
- data/test/background_exception_notification_test.rb +21 -6
- data/test/campfire_test.rb +52 -0
- data/test/dummy/Gemfile +1 -1
- data/test/dummy/Gemfile.lock +93 -58
- data/test/dummy/app/controllers/posts_controller.rb +1 -0
- data/test/dummy/app/views/exception_notifier/_new_bkg_section.html.erb +1 -0
- data/test/dummy/app/views/exception_notifier/_new_section.html.erb +1 -0
- data/test/dummy/app/views/exception_notifier/_new_section.text.erb +1 -1
- data/test/dummy/test/functional/posts_controller_test.rb +62 -10
- data/test/exception_notification_test.rb +27 -2
- data/test/test_helper.rb +3 -0
- metadata +55 -7
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 3.0.0
|
2
|
+
|
3
|
+
* enhancements
|
4
|
+
* Campfire integration
|
5
|
+
* Support fot HTML notifications (by @Xenofex)
|
6
|
+
* Be able to override SMTP settings (by @piglop and @Macint)
|
7
|
+
|
8
|
+
* bug fixes
|
9
|
+
* Fix encoding issues
|
10
|
+
* Allow default sections to be overridden (by @jfarmer)
|
11
|
+
* Don't automatically deliver background notifications
|
12
|
+
|
1
13
|
== 2.6.1
|
2
14
|
|
3
15
|
* bug fixes
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# How to contribute
|
2
|
+
|
3
|
+
We love your contribution, for it's essential for making ExceptionNotification greater every day.
|
4
|
+
In order to keep it as easy as possible to contribute changes, here are a few guidelines that we
|
5
|
+
need contributors to follow:
|
6
|
+
|
7
|
+
## First of all
|
8
|
+
|
9
|
+
* Check if the issue you're going to submit isn't already submitted in
|
10
|
+
the [Issues](https://github.com/smartinez87/exception_notification/issues) page.
|
11
|
+
|
12
|
+
## Issues
|
13
|
+
|
14
|
+
* Submit a ticket for your issue, assuming one does not already exist.
|
15
|
+
* The issue must:
|
16
|
+
* Clearly describe the problem including steps to reproduce when it is a bug.
|
17
|
+
* Also include all the information you can to make it easier for us to reproduce it,
|
18
|
+
like OS version, gem versions, etc...
|
19
|
+
* Even better, provide a failing test case for it.
|
20
|
+
|
21
|
+
## Pull Requests
|
22
|
+
|
23
|
+
If you've gone the extra mile and have a patch that fixes the issue, you
|
24
|
+
should submit a Pull Request!
|
25
|
+
|
26
|
+
* Fork the repo on Github.
|
27
|
+
* Create a topic branch from where you want to base your work.
|
28
|
+
* Add a test for your change. Only refactoring and documentation changes
|
29
|
+
require no new tests. If you are adding functionality or fixing a bug,
|
30
|
+
we need a test!
|
31
|
+
* Run _all_ the tests to assure nothine else was broken. We only take pull requests with passing tests.
|
32
|
+
* Check for unnecessary whitespace with `git diff --check` before committing.
|
33
|
+
* Push to your fork and submit a pull request.
|
data/Gemfile.lock
CHANGED
@@ -1,52 +1,64 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
exception_notification (
|
4
|
+
exception_notification (3.0.0.rc1)
|
5
5
|
actionmailer (>= 3.0.4)
|
6
|
+
tinder (~> 1.8)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
9
10
|
specs:
|
10
|
-
actionmailer (3.2.
|
11
|
-
actionpack (= 3.2.
|
11
|
+
actionmailer (3.2.6)
|
12
|
+
actionpack (= 3.2.6)
|
12
13
|
mail (~> 2.4.4)
|
13
|
-
actionpack (3.2.
|
14
|
-
activemodel (= 3.2.
|
15
|
-
activesupport (= 3.2.
|
14
|
+
actionpack (3.2.6)
|
15
|
+
activemodel (= 3.2.6)
|
16
|
+
activesupport (= 3.2.6)
|
16
17
|
builder (~> 3.0.0)
|
17
18
|
erubis (~> 2.7.0)
|
18
19
|
journey (~> 1.0.1)
|
19
20
|
rack (~> 1.4.0)
|
20
21
|
rack-cache (~> 1.2)
|
21
22
|
rack-test (~> 0.6.1)
|
22
|
-
sprockets (~> 2.1.
|
23
|
-
activemodel (3.2.
|
24
|
-
activesupport (= 3.2.
|
23
|
+
sprockets (~> 2.1.3)
|
24
|
+
activemodel (3.2.6)
|
25
|
+
activesupport (= 3.2.6)
|
25
26
|
builder (~> 3.0.0)
|
26
|
-
activerecord (3.2.
|
27
|
-
activemodel (= 3.2.
|
28
|
-
activesupport (= 3.2.
|
27
|
+
activerecord (3.2.6)
|
28
|
+
activemodel (= 3.2.6)
|
29
|
+
activesupport (= 3.2.6)
|
29
30
|
arel (~> 3.0.2)
|
30
31
|
tzinfo (~> 0.3.29)
|
31
|
-
activeresource (3.2.
|
32
|
-
activemodel (= 3.2.
|
33
|
-
activesupport (= 3.2.
|
34
|
-
activesupport (3.2.
|
32
|
+
activeresource (3.2.6)
|
33
|
+
activemodel (= 3.2.6)
|
34
|
+
activesupport (= 3.2.6)
|
35
|
+
activesupport (3.2.6)
|
35
36
|
i18n (~> 0.6)
|
36
37
|
multi_json (~> 1.0)
|
37
38
|
arel (3.0.2)
|
38
39
|
builder (3.0.0)
|
39
40
|
erubis (2.7.0)
|
41
|
+
eventmachine (1.0.0)
|
42
|
+
faraday (0.8.4)
|
43
|
+
multipart-post (~> 1.1)
|
44
|
+
faraday_middleware (0.8.8)
|
45
|
+
faraday (>= 0.7.4, < 0.9)
|
46
|
+
hashie (1.2.0)
|
40
47
|
hike (1.2.1)
|
48
|
+
http_parser.rb (0.5.3)
|
41
49
|
i18n (0.6.0)
|
42
|
-
journey (1.0.
|
43
|
-
json (1.
|
50
|
+
journey (1.0.4)
|
51
|
+
json (1.7.3)
|
44
52
|
mail (2.4.4)
|
45
53
|
i18n (>= 0.4.0)
|
46
54
|
mime-types (~> 1.16)
|
47
55
|
treetop (~> 1.4.8)
|
48
|
-
|
49
|
-
|
56
|
+
metaclass (0.0.1)
|
57
|
+
mime-types (1.19)
|
58
|
+
mocha (0.12.0)
|
59
|
+
metaclass (~> 0.0.1)
|
60
|
+
multi_json (1.3.6)
|
61
|
+
multipart-post (1.1.5)
|
50
62
|
polyglot (0.3.3)
|
51
63
|
rack (1.4.1)
|
52
64
|
rack-cache (1.2)
|
@@ -55,34 +67,49 @@ GEM
|
|
55
67
|
rack
|
56
68
|
rack-test (0.6.1)
|
57
69
|
rack (>= 1.0)
|
58
|
-
rails (3.2.
|
59
|
-
actionmailer (= 3.2.
|
60
|
-
actionpack (= 3.2.
|
61
|
-
activerecord (= 3.2.
|
62
|
-
activeresource (= 3.2.
|
63
|
-
activesupport (= 3.2.
|
70
|
+
rails (3.2.6)
|
71
|
+
actionmailer (= 3.2.6)
|
72
|
+
actionpack (= 3.2.6)
|
73
|
+
activerecord (= 3.2.6)
|
74
|
+
activeresource (= 3.2.6)
|
75
|
+
activesupport (= 3.2.6)
|
64
76
|
bundler (~> 1.0)
|
65
|
-
railties (= 3.2.
|
66
|
-
railties (3.2.
|
67
|
-
actionpack (= 3.2.
|
68
|
-
activesupport (= 3.2.
|
77
|
+
railties (= 3.2.6)
|
78
|
+
railties (3.2.6)
|
79
|
+
actionpack (= 3.2.6)
|
80
|
+
activesupport (= 3.2.6)
|
69
81
|
rack-ssl (~> 1.3.2)
|
70
82
|
rake (>= 0.8.7)
|
71
83
|
rdoc (~> 3.4)
|
72
|
-
thor (
|
84
|
+
thor (>= 0.14.6, < 2.0)
|
73
85
|
rake (0.9.2.2)
|
74
86
|
rdoc (3.12)
|
75
87
|
json (~> 1.4)
|
76
|
-
|
88
|
+
simple_oauth (0.1.9)
|
89
|
+
sprockets (2.1.3)
|
77
90
|
hike (~> 1.2)
|
78
91
|
rack (~> 1.0)
|
79
92
|
tilt (~> 1.1, != 1.3.0)
|
80
93
|
sqlite3 (1.3.6)
|
81
|
-
thor (0.
|
94
|
+
thor (0.15.4)
|
82
95
|
tilt (1.3.3)
|
96
|
+
tinder (1.9.1)
|
97
|
+
eventmachine (>= 0.12.0, < 2)
|
98
|
+
faraday (~> 0.8)
|
99
|
+
faraday_middleware (~> 0.8)
|
100
|
+
hashie (~> 1.0)
|
101
|
+
json (~> 1.6)
|
102
|
+
mime-types (~> 1.16)
|
103
|
+
multi_json (~> 1.0)
|
104
|
+
multipart-post (~> 1.1)
|
105
|
+
twitter-stream (~> 0.1)
|
83
106
|
treetop (1.4.10)
|
84
107
|
polyglot
|
85
108
|
polyglot (>= 0.3.1)
|
109
|
+
twitter-stream (0.1.16)
|
110
|
+
eventmachine (>= 0.12.8)
|
111
|
+
http_parser.rb (~> 0.5.1)
|
112
|
+
simple_oauth (~> 0.1.4)
|
86
113
|
tzinfo (0.3.33)
|
87
114
|
|
88
115
|
PLATFORMS
|
@@ -90,5 +117,6 @@ PLATFORMS
|
|
90
117
|
|
91
118
|
DEPENDENCIES
|
92
119
|
exception_notification!
|
120
|
+
mocha (>= 0.11.3)
|
93
121
|
rails (>= 3.0.4)
|
94
122
|
sqlite3 (>= 1.3.4)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Exception Notifier Plugin for Rails  [](http://travis-ci.org/smartinez87/exception_notification)
|
1
|
+
Exception Notifier Plugin for Rails  [](http://travis-ci.org/smartinez87/exception_notification) [](https://codeclimate.com/github/smartinez87/exception_notification)
|
2
2
|
====
|
3
3
|
|
4
4
|
The Exception Notifier plugin provides a mailer object and a default set of
|
@@ -35,6 +35,25 @@ Whatever::Application.config.middleware.use ExceptionNotifier,
|
|
35
35
|
:exception_recipients => %w{exceptions@example.com}
|
36
36
|
```
|
37
37
|
|
38
|
+
Campfire Integration
|
39
|
+
---
|
40
|
+
|
41
|
+
Additionally, ExceptionNotification supports sending notifications to
|
42
|
+
your Campfire room.
|
43
|
+
To configure it, you need to set the subdomain, token and room name,
|
44
|
+
like this
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
Whatever::Application.config.middleware.use ExceptionNotifier,
|
48
|
+
:email_prefix => "[Whatever] ",
|
49
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
50
|
+
:exception_recipients => %w{exceptions@example.com},
|
51
|
+
:campfire => {:subdomain => 'my_subdomain', :token => 'my_token', :room_name => 'my_room'}
|
52
|
+
```
|
53
|
+
|
54
|
+
For more options to set Campfire, like _ssl_, check
|
55
|
+
[here](https://github.com/collectiveidea/tinder/blob/master/lib/tinder/campfire.rb#L17).
|
56
|
+
|
38
57
|
Customization
|
39
58
|
---
|
40
59
|
|
@@ -47,7 +66,7 @@ app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has
|
|
47
66
|
access to the following variables:
|
48
67
|
|
49
68
|
```ruby
|
50
|
-
@
|
69
|
+
@kontroller # the controller that caused the error
|
51
70
|
@request # the current request object
|
52
71
|
@exception # the exception that was raised
|
53
72
|
@backtrace # a sanitized version of the exception's backtrace
|
@@ -55,7 +74,7 @@ access to the following variables:
|
|
55
74
|
@sections # the array of sections to include in the email
|
56
75
|
```
|
57
76
|
|
58
|
-
Background views will not have access to @
|
77
|
+
Background views will not have access to @kontroller and @request.
|
59
78
|
|
60
79
|
You can reorder the sections, or exclude sections completely, by altering the
|
61
80
|
ExceptionNotifier.sections variable. You can even add new sections that
|
@@ -71,6 +90,9 @@ Whatever::Application.config.middleware.use ExceptionNotifier,
|
|
71
90
|
:sections => %w{my_section1 my_section2} + ExceptionNotifier::Notifier.default_sections
|
72
91
|
```
|
73
92
|
|
93
|
+
Place your custom sections under `./app/views/exception_notifier/` with the suffix `.text.erb`, e.g.
|
94
|
+
`./app/views/exception_notifier/_my_section1.text.erb`.
|
95
|
+
|
74
96
|
If your new section requires information that isn't available by default, make sure
|
75
97
|
it is made available to the email using the exception_data macro:
|
76
98
|
|
@@ -181,6 +203,11 @@ You can also choose to remove numbers from subject so they thread as a single on
|
|
181
203
|
This is disabled by default.
|
182
204
|
Use _:normalize_subject => true_ to enable it.
|
183
205
|
|
206
|
+
### HTML
|
207
|
+
|
208
|
+
You may want to send multipart notifications instead of just plain text, which ExceptionNotification sends by default.
|
209
|
+
You can do so by adding this to the configuration: _:email_format => :html_.
|
210
|
+
|
184
211
|
|
185
212
|
Background Notifications
|
186
213
|
---
|
@@ -193,7 +220,7 @@ like this:
|
|
193
220
|
begin
|
194
221
|
some code...
|
195
222
|
rescue => e
|
196
|
-
ExceptionNotifier::Notifier.background_exception_notification(e)
|
223
|
+
ExceptionNotifier::Notifier.background_exception_notification(e).deliver
|
197
224
|
end
|
198
225
|
```
|
199
226
|
|
@@ -205,7 +232,7 @@ begin
|
|
205
232
|
some code...
|
206
233
|
rescue => exception
|
207
234
|
ExceptionNotifier::Notifier.background_exception_notification(exception,
|
208
|
-
:data => {:worker => worker.to_s, :queue => queue, :payload => payload})
|
235
|
+
:data => {:worker => worker.to_s, :queue => queue, :payload => payload}).deliver
|
209
236
|
end
|
210
237
|
```
|
211
238
|
|
@@ -231,12 +258,33 @@ Notification
|
|
231
258
|
---
|
232
259
|
|
233
260
|
After an exception notification has been delivered the rack environment variable
|
234
|
-
'exception_notifier.delivered' will be set to
|
261
|
+
'exception_notifier.delivered' will be set to `true`.
|
262
|
+
|
263
|
+
|
264
|
+
Override SMTP settings
|
265
|
+
---
|
266
|
+
|
267
|
+
You can use specific SMTP settings for notifications:
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
Whatever::Application.config.middleware.use ExceptionNotifier,
|
271
|
+
:email_prefix => "[Whatever] ",
|
272
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
273
|
+
:exception_recipients => %w{exceptions@example.com},
|
274
|
+
:smtp_settings => {
|
275
|
+
:user_name => "bob",
|
276
|
+
:password => "password",
|
277
|
+
}
|
278
|
+
```
|
235
279
|
|
236
280
|
Versions
|
237
281
|
---
|
238
282
|
|
239
|
-
NOTE: Master branch is currently set for
|
283
|
+
NOTE: Master branch is currently set for v3.0.0
|
284
|
+
|
285
|
+
For v2.6.1, see this tag:
|
286
|
+
|
287
|
+
<a href="http://github.com/smartinez87/exception_notification/tree/v2.6.1">http://github.com/smartinez87/exception_notification/tree/v2.6.1</a>
|
240
288
|
|
241
289
|
For v2.6.0, see this tag:
|
242
290
|
|
@@ -246,10 +294,6 @@ For v2.5.2, see this tag:
|
|
246
294
|
|
247
295
|
<a href="http://github.com/smartinez87/exception_notification/tree/v2.5.2">http://github.com/smartinez87/exception_notification/tree/v2.5.2</a>
|
248
296
|
|
249
|
-
For v2.5.0, see tag:
|
250
|
-
|
251
|
-
<a href="http://github.com/smartinez87/exception_notification/tree/v2.5.0">http://github.com/smartinez87/exception_notification/tree/v2.5.0</a>
|
252
|
-
|
253
297
|
For previous releases, visit:
|
254
298
|
|
255
299
|
<a href="https://github.com/smartinez87/exception_notification/tags">https://github.com/smartinez87/exception_notification/tags</a>
|
@@ -265,6 +309,9 @@ If you are running pre-rack Rails then see this tag:
|
|
265
309
|
Support and tickets
|
266
310
|
---
|
267
311
|
|
268
|
-
|
312
|
+
Here's the list of [issues](https://github.com/smartinez87/exception_notification/issues) we're currently working on.
|
313
|
+
|
314
|
+
To contribute, please read first the [Contributing
|
315
|
+
Guide](https://github.com/smartinez87/exception_notification/blob/master/CONTRIBUTING.md).
|
269
316
|
|
270
317
|
Copyright (c) 2005 Jamis Buck, released under the MIT license: <a href="http://www.opensource.org/licenses/MIT">http://www.opensource.org/licenses/MIT</a>
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'exception_notification'
|
3
|
-
s.version = '
|
3
|
+
s.version = '3.0.0.rc1'
|
4
4
|
s.authors = ["Jamis Buck", "Josh Peek"]
|
5
|
-
s.date = %q{2012-
|
6
|
-
s.summary = "Exception notification
|
5
|
+
s.date = %q{2012-10-05}
|
6
|
+
s.summary = "Exception notification for Rails apps"
|
7
7
|
s.homepage = "http://smartinez87.github.com/exception_notification"
|
8
8
|
s.email = "smartinez87@gmail.com"
|
9
9
|
|
@@ -12,6 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.require_path = 'lib'
|
13
13
|
|
14
14
|
s.add_dependency("actionmailer", ">= 3.0.4")
|
15
|
+
s.add_dependency("tinder", "~> 1.8")
|
15
16
|
s.add_development_dependency "rails", ">= 3.0.4"
|
17
|
+
s.add_development_dependency "mocha", ">= 0.11.3"
|
16
18
|
s.add_development_dependency "sqlite3", ">= 1.3.4"
|
17
19
|
end
|
data/lib/exception_notifier.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'action_dispatch'
|
2
2
|
require 'exception_notifier/notifier'
|
3
|
+
require 'exception_notifier/campfire_notifier'
|
3
4
|
|
4
5
|
class ExceptionNotifier
|
6
|
+
|
5
7
|
def self.default_ignore_exceptions
|
6
8
|
[].tap do |exceptions|
|
7
9
|
exceptions << 'ActiveRecord::RecordNotFound'
|
@@ -20,10 +22,14 @@ class ExceptionNotifier
|
|
20
22
|
Notifier.default_sender_address = @options[:sender_address]
|
21
23
|
Notifier.default_exception_recipients = @options[:exception_recipients]
|
22
24
|
Notifier.default_email_prefix = @options[:email_prefix]
|
25
|
+
Notifier.default_email_format = @options[:email_format]
|
23
26
|
Notifier.default_sections = @options[:sections]
|
24
27
|
Notifier.default_background_sections = @options[:background_sections]
|
25
28
|
Notifier.default_verbose_subject = @options[:verbose_subject]
|
26
29
|
Notifier.default_normalize_subject = @options[:normalize_subject]
|
30
|
+
Notifier.default_smtp_settings = @options[:smtp_settings]
|
31
|
+
|
32
|
+
@campfire = CampfireNotifier.new @options[:campfire]
|
27
33
|
|
28
34
|
@options[:ignore_exceptions] ||= self.class.default_ignore_exceptions
|
29
35
|
@options[:ignore_crawlers] ||= self.class.default_ignore_crawlers
|
@@ -40,6 +46,7 @@ class ExceptionNotifier
|
|
40
46
|
from_crawler(options[:ignore_crawlers], env['HTTP_USER_AGENT']) ||
|
41
47
|
conditionally_ignored(options[:ignore_if], env, exception)
|
42
48
|
Notifier.exception_notification(env, exception).deliver
|
49
|
+
@campfire.exception_notification(exception)
|
43
50
|
env['exception_notifier.delivered'] = true
|
44
51
|
end
|
45
52
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class ExceptionNotifier
|
2
|
+
class CampfireNotifier
|
3
|
+
require 'tinder'
|
4
|
+
|
5
|
+
attr_accessor :subdomain
|
6
|
+
attr_accessor :token
|
7
|
+
attr_accessor :room
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
begin
|
11
|
+
subdomain = options.delete(:subdomain)
|
12
|
+
room_name = options.delete(:room_name)
|
13
|
+
@campfire = Tinder::Campfire.new subdomain, options
|
14
|
+
@room = @campfire.find_room_by_name room_name
|
15
|
+
rescue
|
16
|
+
@campfire = @room = nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def exception_notification(exception)
|
21
|
+
@room.paste "A new exception occurred: '#{exception.message}' on '#{exception.backtrace.first}'" if active?
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def active?
|
27
|
+
!@room.nil?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -12,10 +12,12 @@ class ExceptionNotifier
|
|
12
12
|
attr_writer :default_sender_address
|
13
13
|
attr_writer :default_exception_recipients
|
14
14
|
attr_writer :default_email_prefix
|
15
|
+
attr_writer :default_email_format
|
15
16
|
attr_writer :default_sections
|
16
17
|
attr_writer :default_background_sections
|
17
18
|
attr_writer :default_verbose_subject
|
18
19
|
attr_writer :default_normalize_subject
|
20
|
+
attr_writer :default_smtp_settings
|
19
21
|
|
20
22
|
def default_sender_address
|
21
23
|
@default_sender_address || %("Exception Notifier" <exception.notifier@default.com>)
|
@@ -29,6 +31,10 @@ class ExceptionNotifier
|
|
29
31
|
@default_email_prefix || "[ERROR] "
|
30
32
|
end
|
31
33
|
|
34
|
+
def default_email_format
|
35
|
+
@default_email_format || :text
|
36
|
+
end
|
37
|
+
|
32
38
|
def default_sections
|
33
39
|
@default_sections || %w(request session environment backtrace)
|
34
40
|
end
|
@@ -45,14 +51,21 @@ class ExceptionNotifier
|
|
45
51
|
@default_normalize_prefix || false
|
46
52
|
end
|
47
53
|
|
54
|
+
def default_smtp_settings
|
55
|
+
@default_smtp_settings || nil
|
56
|
+
end
|
57
|
+
|
48
58
|
def default_options
|
49
59
|
{ :sender_address => default_sender_address,
|
50
60
|
:exception_recipients => default_exception_recipients,
|
51
61
|
:email_prefix => default_email_prefix,
|
62
|
+
:email_format => default_email_format,
|
52
63
|
:sections => default_sections,
|
53
64
|
:background_sections => default_background_sections,
|
54
65
|
:verbose_subject => default_verbose_subject,
|
55
|
-
:normalize_subject => default_normalize_subject
|
66
|
+
:normalize_subject => default_normalize_subject,
|
67
|
+
:template_path => mailer_name,
|
68
|
+
:smtp_settings => default_smtp_settings }
|
56
69
|
end
|
57
70
|
|
58
71
|
def normalize_digits(string)
|
@@ -66,60 +79,52 @@ class ExceptionNotifier
|
|
66
79
|
end
|
67
80
|
|
68
81
|
def exception_notification(env, exception, options={})
|
69
|
-
|
82
|
+
load_custom_views
|
70
83
|
|
71
84
|
@env = env
|
72
85
|
@exception = exception
|
73
|
-
@options = (env['exception_notifier.options'] || {}).reverse_merge(self.class.default_options)
|
86
|
+
@options = options.reverse_merge(env['exception_notifier.options'] || {}).reverse_merge(self.class.default_options)
|
74
87
|
@kontroller = env['action_controller.instance'] || MissingController.new
|
75
88
|
@request = ActionDispatch::Request.new(env)
|
76
89
|
@backtrace = exception.backtrace ? clean_backtrace(exception) : []
|
77
90
|
@sections = @options[:sections]
|
78
91
|
@data = (env['exception_notifier.exception_data'] || {}).merge(options[:data] || {})
|
79
92
|
@sections = @sections + %w(data) unless @data.empty?
|
80
|
-
|
81
|
-
|
82
|
-
instance_variable_set("@#{name}", value)
|
83
|
-
end
|
84
|
-
subject = compose_subject(exception, @kontroller)
|
85
|
-
|
86
|
-
mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
|
87
|
-
format.text { render "#{mailer_name}/exception_notification" }
|
88
|
-
end
|
93
|
+
|
94
|
+
compose_email
|
89
95
|
end
|
90
96
|
|
91
97
|
def background_exception_notification(exception, options={})
|
92
|
-
|
98
|
+
load_custom_views
|
93
99
|
|
94
100
|
if @notifier = Rails.application.config.middleware.detect{ |x| x.klass == ExceptionNotifier }
|
95
|
-
@options = (@notifier.args.first || {}).reverse_merge(self.class.default_options)
|
101
|
+
@options = options.reverse_merge(@notifier.args.first || {}).reverse_merge(self.class.default_options)
|
96
102
|
@exception = exception
|
97
103
|
@backtrace = exception.backtrace || []
|
98
104
|
@sections = @options[:background_sections]
|
99
105
|
@data = options[:data] || {}
|
100
106
|
|
101
|
-
|
102
|
-
instance_variable_set("@#{name}", value)
|
103
|
-
end
|
104
|
-
subject = compose_subject(exception)
|
105
|
-
|
106
|
-
mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
|
107
|
-
format.text { render "#{mailer_name}/background_exception_notification" }
|
108
|
-
end.deliver
|
107
|
+
compose_email
|
109
108
|
end
|
110
109
|
end
|
111
110
|
|
112
111
|
private
|
113
112
|
|
114
|
-
def compose_subject
|
113
|
+
def compose_subject
|
115
114
|
subject = "#{@options[:email_prefix]}"
|
116
|
-
subject << "#{kontroller.controller_name}##{kontroller.action_name}" if kontroller
|
117
|
-
subject << " (#{exception.class})"
|
118
|
-
subject << " #{exception.message.inspect}" if @options[:verbose_subject]
|
115
|
+
subject << "#{@kontroller.controller_name}##{@kontroller.action_name}" if @kontroller
|
116
|
+
subject << " (#{@exception.class})"
|
117
|
+
subject << " #{@exception.message.inspect}" if @options[:verbose_subject]
|
119
118
|
subject = normalize_digits(subject) if @options[:normalize_subject]
|
120
119
|
subject.length > 120 ? subject[0...120] + "..." : subject
|
121
120
|
end
|
122
121
|
|
122
|
+
def set_data_variables
|
123
|
+
@data.each do |name, value|
|
124
|
+
instance_variable_set("@#{name}", value)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
123
128
|
def clean_backtrace(exception)
|
124
129
|
if Rails.respond_to?(:backtrace_cleaner)
|
125
130
|
Rails.backtrace_cleaner.send(:filter, exception.backtrace)
|
@@ -140,5 +145,29 @@ class ExceptionNotifier
|
|
140
145
|
object.to_s
|
141
146
|
end
|
142
147
|
end
|
148
|
+
|
149
|
+
def html_mail?
|
150
|
+
@options[:email_format] == :html
|
151
|
+
end
|
152
|
+
|
153
|
+
def compose_email
|
154
|
+
set_data_variables
|
155
|
+
subject = compose_subject
|
156
|
+
name = @env.nil? ? 'background_exception_notification' : 'exception_notification'
|
157
|
+
|
158
|
+
mail = mail(:to => @options[:exception_recipients], :from => @options[:sender_address],
|
159
|
+
:subject => subject, :template_name => name) do |format|
|
160
|
+
format.text
|
161
|
+
format.html if html_mail?
|
162
|
+
end
|
163
|
+
|
164
|
+
mail.delivery_method.settings.merge!(@options[:smtp_settings]) if @options[:smtp_settings]
|
165
|
+
|
166
|
+
mail
|
167
|
+
end
|
168
|
+
|
169
|
+
def load_custom_views
|
170
|
+
self.prepend_view_path Rails.root.nil? ? "app/views" : "#{Rails.root}/app/views" if defined?(Rails)
|
171
|
+
end
|
143
172
|
end
|
144
173
|
end
|