exception_notification 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ Exception Notifier Plugin for Rails
2
+ ====
3
+
4
+ The Exception Notifier plugin provides a mailer object and a default set of
5
+ templates for sending email notifications when errors occur in a Rails
6
+ application. The plugin is configurable, allowing programmers to specify:
7
+
8
+ * the sender address of the email
9
+ * the recipient addresses
10
+ * the text used to prefix the subject line
11
+
12
+ The email includes information about the current request, session, and
13
+ environment, and also gives a backtrace of the exception.
14
+
15
+ Installation
16
+ ---
17
+
18
+ You can use the latest ExceptionNotification gem with Rails 3, by adding
19
+ the following line in your Gemfile
20
+
21
+ gem 'exception_notification', :require => 'exception_notifier'
22
+
23
+ As of Rails 3 ExceptionNotification is used as a rack middleware, so you can
24
+ configure its options on your config.ru file, or in the environment you
25
+ want it to run. In most cases you would want ExceptionNotification to
26
+ run on production. You can make it work by
27
+
28
+ Whatever::Application.config.middleware.use ExceptionNotifier,
29
+ :email_prefix => "[Whatever] ",
30
+ :sender_address => %{"notifier" <notifier@example.com>},
31
+ :exception_recipients => %w{exceptions@example.com}
32
+
33
+ Customization
34
+ ---
35
+
36
+ By default, the notification email includes four parts: request, session,
37
+ environment, and backtrace (in that order). You can customize how each of those
38
+ sections are rendered by placing a partial named for that part in your
39
+ app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has
40
+ access to the following variables:
41
+
42
+ @controller # the controller that caused the error
43
+ @request # the current request object
44
+ @exception # the exception that was raised
45
+ @backtrace # a sanitized version of the exception's backtrace
46
+ @data # a hash of optional data values that were passed to the notifier
47
+ @sections # the array of sections to include in the email
48
+
49
+ You can reorder the sections, or exclude sections completely, by altering the
50
+ ExceptionNotifier.sections variable. You can even add new sections that
51
+ describe application-specific data--just add the section's name to the list
52
+ (whereever you'd like), and define the corresponding partial. Then, if your
53
+ new section requires information that isn't available by default, make sure
54
+ it is made available to the email using the exception_data macro:
55
+
56
+ class ApplicationController < ActionController::Base
57
+ before_filter :log_additional_data
58
+ ...
59
+ protected
60
+ def log_additional_data
61
+ request.env["exception_notifier.exception_data"] = {
62
+ :document => @document,
63
+ :person => @person
64
+ }
65
+ end
66
+ ...
67
+ end
68
+
69
+ In the above case, @document and @person would be made available to the email
70
+ renderer, allowing your new section(s) to access and display them. See the
71
+ existing sections defined by the plugin for examples of how to write your own.
72
+
73
+ Notification
74
+ ---
75
+
76
+ After an exception notification has been delivered the rack environment variable
77
+ 'exception_notifier.delivered' will be set to +true+.
78
+
79
+ Rails 2.3 stable and earlier
80
+ ---
81
+
82
+ If you are running Rails 2.3 then see the branch for that:
83
+
84
+ <a href="http://github.com/smartinez87/exception_notification/tree/2-3-stable">http://github.com/smartinez87/exception_notification/tree/2-3-stable</a>
85
+
86
+ If you are running pre-rack Rails then see this tag:
87
+
88
+ <a href="http://github.com/smartinez87/exception_notification/tree/pre-2-3">http://github.com/smartinez87/exception_notification/tree/pre-2-3</a>
89
+
90
+ Support and tickets
91
+ ---
92
+
93
+ <a href="https://github.com/smartinez87/exception_notification/issues">https://github.com/smartinez87/exception_notification/issues</a>
94
+
95
+ Copyright (c) 2005 Jamis Buck, released under the MIT license
@@ -0,0 +1 @@
1
+ require 'exception_notifier'
@@ -12,13 +12,19 @@ class ExceptionNotifier
12
12
 
13
13
  def initialize(app, options = {})
14
14
  @app, @options = app, options
15
+
16
+ Notifier.default_sender_address = @options[:sender_address]
17
+ Notifier.default_exception_recipients = @options[:exception_recipients]
18
+ Notifier.default_email_prefix = @options[:email_prefix]
19
+ Notifier.default_sections = @options[:sections]
20
+
15
21
  @options[:ignore_exceptions] ||= self.class.default_ignore_exceptions
16
22
  end
17
23
 
18
24
  def call(env)
19
25
  @app.call(env)
20
26
  rescue Exception => exception
21
- options = (env['exception_notifier.options'] ||= {})
27
+ options = (env['exception_notifier.options'] ||= Notifier.default_options)
22
28
  options.reverse_merge!(@options)
23
29
 
24
30
  unless Array.wrap(options[:ignore_exceptions]).include?(exception.class)
@@ -7,20 +7,25 @@ class ExceptionNotifier
7
7
  self.append_view_path "#{File.dirname(__FILE__)}/views"
8
8
 
9
9
  class << self
10
+ attr_writer :default_sender_address
11
+ attr_writer :default_exception_recipients
12
+ attr_writer :default_email_prefix
13
+ attr_writer :default_sections
14
+
10
15
  def default_sender_address
11
- %("Exception Notifier" <exception.notifier@default.com>)
16
+ @default_sender_address || %("Exception Notifier" <exception.notifier@default.com>)
12
17
  end
13
18
 
14
19
  def default_exception_recipients
15
- []
20
+ @default_exception_recipients || []
16
21
  end
17
22
 
18
23
  def default_email_prefix
19
- "[ERROR] "
24
+ @default_email_prefix || "[ERROR] "
20
25
  end
21
26
 
22
27
  def default_sections
23
- %w(request session environment backtrace)
28
+ @default_sections || %w(request session environment backtrace)
24
29
  end
25
30
 
26
31
  def default_options
@@ -52,6 +57,7 @@ class ExceptionNotifier
52
57
 
53
58
  prefix = "#{@options[:email_prefix]}#{@kontroller.controller_name}##{@kontroller.action_name}"
54
59
  subject = "#{prefix} (#{@exception.class}) #{@exception.message.inspect}"
60
+ subject = subject.length > 120 ? subject[0...120] + "..." : subject
55
61
 
56
62
  mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
57
63
  format.text { render "#{mailer_name}/exception_notification" }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_notification
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 4
9
- - 0
10
- version: 2.4.0
9
+ - 1
10
+ version: 2.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jamis Buck
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-09 00:00:00 -02:00
20
- default_executable:
19
+ date: 2011-06-09 00:00:00 Z
21
20
  dependencies: []
22
21
 
23
22
  description:
@@ -29,16 +28,16 @@ extensions: []
29
28
  extra_rdoc_files: []
30
29
 
31
30
  files:
32
- - README
31
+ - README.md
32
+ - lib/exception_notification.rb
33
33
  - lib/exception_notifier/notifier.rb
34
- - lib/exception_notifier/views/exception_notifier/_request.text.erb
34
+ - lib/exception_notifier/views/exception_notifier/_backtrace.text.erb
35
35
  - lib/exception_notifier/views/exception_notifier/_environment.text.erb
36
+ - lib/exception_notifier/views/exception_notifier/_request.text.erb
36
37
  - lib/exception_notifier/views/exception_notifier/_session.text.erb
37
- - lib/exception_notifier/views/exception_notifier/exception_notification.text.erb
38
- - lib/exception_notifier/views/exception_notifier/_backtrace.text.erb
39
38
  - lib/exception_notifier/views/exception_notifier/_title.text.erb
39
+ - lib/exception_notifier/views/exception_notifier/exception_notification.text.erb
40
40
  - lib/exception_notifier.rb
41
- has_rdoc: true
42
41
  homepage:
43
42
  licenses: []
44
43
 
@@ -68,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
67
  requirements: []
69
68
 
70
69
  rubyforge_project:
71
- rubygems_version: 1.5.2
70
+ rubygems_version: 1.7.1
72
71
  signing_key:
73
72
  specification_version: 3
74
73
  summary: Exception notification by email for Rails apps
data/README DELETED
@@ -1,81 +0,0 @@
1
- = Exception Notifier Plugin for Rails
2
-
3
- The Exception Notifier plugin provides a mailer object and a default set of
4
- templates for sending email notifications when errors occur in a Rails
5
- application. The plugin is configurable, allowing programmers to specify:
6
-
7
- * the sender address of the email
8
- * the recipient addresses
9
- * the text used to prefix the subject line
10
-
11
- The email includes information about the current request, session, and
12
- environment, and also gives a backtrace of the exception.
13
-
14
- == Usage
15
-
16
- As of Rails 3 ExceptionNotifier is used as a rack middleware
17
-
18
- Whatever::Application.config.middleware.use ExceptionNotifier,
19
- :email_prefix => "[Whatever] ",
20
- :sender_address => %{"notifier" <notifier@example.com>},
21
- :exception_recipients => %w{exceptions@example.com}
22
-
23
- == Customization
24
-
25
- By default, the notification email includes four parts: request, session,
26
- environment, and backtrace (in that order). You can customize how each of those
27
- sections are rendered by placing a partial named for that part in your
28
- app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has
29
- access to the following variables:
30
-
31
- * @controller: the controller that caused the error
32
- * @request: the current request object
33
- * @exception: the exception that was raised
34
- * @backtrace: a sanitized version of the exception's backtrace
35
- * @data: a hash of optional data values that were passed to the notifier
36
- * @sections: the array of sections to include in the email
37
-
38
- You can reorder the sections, or exclude sections completely, by altering the
39
- ExceptionNotifier.sections variable. You can even add new sections that
40
- describe application-specific data--just add the section's name to the list
41
- (whereever you'd like), and define the corresponding partial. Then, if your
42
- new section requires information that isn't available by default, make sure
43
- it is made available to the email using the exception_data macro:
44
-
45
- class ApplicationController < ActionController::Base
46
- before_filter :log_additional_data
47
- ...
48
- protected
49
- def log_additional_data
50
- request.env["exception_notifier.exception_data"] = {
51
- :document => @document,
52
- :person => @person
53
- }
54
- end
55
- ...
56
- end
57
-
58
- In the above case, @document and @person would be made available to the email
59
- renderer, allowing your new section(s) to access and display them. See the
60
- existing sections defined by the plugin for examples of how to write your own.
61
-
62
- == Notification
63
-
64
- After an exception notification has been delivered the rack environment variable
65
- 'exception_notifier.delivered' will be set to +true+.
66
-
67
- == Rails 2.3 stable and earlier
68
-
69
- If you are running Rails 2.3 then see the branch for that:
70
-
71
- http://github.com/rails/exception_notification/tree/2-3-stable
72
-
73
- If you are running pre-rack Rails then see this tag:
74
-
75
- http://github.com/rails/exception_notification/tree/pre-2-3
76
-
77
- == Support and tickets
78
-
79
- https://github.com/smartinez87/exception_notification/issues
80
-
81
- Copyright (c) 2005 Jamis Buck, released under the MIT license