mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
Added exception notifier plugin.
This commit is contained in:
parent
e9df965498
commit
5c4e32756b
3
Gemfile
3
Gemfile
@ -29,8 +29,9 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
|
|||||||
# gem 'webrat'
|
# gem 'webrat'
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier'
|
||||||
gem 'pg'
|
gem 'pg'
|
||||||
gem 'typus', :git => 'git://github.com/fesplugas/typus.git'
|
gem 'typus', :git => 'git://github.com/fesplugas/typus.git'
|
||||||
gem 'mini_exiftool'
|
gem 'mini_exiftool'
|
||||||
gem 'will_paginate', :git => 'http://github.com/mislav/will_paginate.git', :branch => 'rails3'
|
gem 'will_paginate', :git => 'http://github.com/mislav/will_paginate.git', :branch => 'rails3'
|
||||||
gem 'rdiscount'
|
gem 'rdiscount'
|
||||||
|
|||||||
@ -4,6 +4,12 @@ GIT
|
|||||||
specs:
|
specs:
|
||||||
typus (1.0.0.pre8)
|
typus (1.0.0.pre8)
|
||||||
|
|
||||||
|
GIT
|
||||||
|
remote: git://github.com/rails/exception_notification
|
||||||
|
revision: 192a49a02d63d28b23ed41cebadfedd490929cf1
|
||||||
|
specs:
|
||||||
|
exception_notification (1.0.0)
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: http://github.com/mislav/will_paginate.git
|
remote: http://github.com/mislav/will_paginate.git
|
||||||
revision: b1a5beeec9f56ecbe3594fcdca76d92b6767ce50
|
revision: b1a5beeec9f56ecbe3594fcdca76d92b6767ce50
|
||||||
@ -85,6 +91,7 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
exception_notification!
|
||||||
mini_exiftool
|
mini_exiftool
|
||||||
pg
|
pg
|
||||||
rails (= 3.0.0)
|
rails (= 3.0.0)
|
||||||
|
|||||||
@ -38,7 +38,13 @@ module Photos
|
|||||||
|
|
||||||
# Configure sensitive parameters which will be filtered from the log file.
|
# Configure sensitive parameters which will be filtered from the log file.
|
||||||
config.filter_parameters += [:password]
|
config.filter_parameters += [:password]
|
||||||
|
|
||||||
|
# Rack Middleware
|
||||||
|
config.middleware.use ::ExceptionNotifier, :email_prefix => "[DanBarberPhoto] ",
|
||||||
|
:sender_address => %{"Exception Notification" <notifier@danbarberphoto.com>},
|
||||||
|
:exception_recipients => %w{dan@danbarberphoto.com}
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ActionMailer::Base.delivery_method = :sendmail
|
ActionMailer::Base.delivery_method = :sendmail
|
||||||
|
|||||||
8672
log/development.log
8672
log/development.log
File diff suppressed because it is too large
Load Diff
81
vendor/plugins/exception_notification/README
vendored
Normal file
81
vendor/plugins/exception_notification/README
vendored
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
= Exception Notifier Plugin for Rails
|
||||||
|
|
||||||
|
The Exception Notifier plugin provides a mailer object and a default set of
|
||||||
|
templates for sending email notifications when errors occur in a Rails
|
||||||
|
application. The plugin is configurable, allowing programmers to specify:
|
||||||
|
|
||||||
|
* the sender address of the email
|
||||||
|
* the recipient addresses
|
||||||
|
* the text used to prefix the subject line
|
||||||
|
|
||||||
|
The email includes information about the current request, session, and
|
||||||
|
environment, and also gives a backtrace of the exception.
|
||||||
|
|
||||||
|
== Usage
|
||||||
|
|
||||||
|
As of Rails 3 ExceptionNotifier is used as a rack middleware
|
||||||
|
|
||||||
|
Whatever::Application.config.middleware.use ExceptionNotifier,
|
||||||
|
:email_prefix => "[Whatever] ",
|
||||||
|
:sender_address => %{"notifier" <notifier@example.com>},
|
||||||
|
:exception_recipients => %w{exceptions@example.com}
|
||||||
|
|
||||||
|
== Customization
|
||||||
|
|
||||||
|
By default, the notification email includes four parts: request, session,
|
||||||
|
environment, and backtrace (in that order). You can customize how each of those
|
||||||
|
sections are rendered by placing a partial named for that part in your
|
||||||
|
app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has
|
||||||
|
access to the following variables:
|
||||||
|
|
||||||
|
* @controller: the controller that caused the error
|
||||||
|
* @request: the current request object
|
||||||
|
* @exception: the exception that was raised
|
||||||
|
* @backtrace: a sanitized version of the exception's backtrace
|
||||||
|
* @data: a hash of optional data values that were passed to the notifier
|
||||||
|
* @sections: the array of sections to include in the email
|
||||||
|
|
||||||
|
You can reorder the sections, or exclude sections completely, by altering the
|
||||||
|
ExceptionNotifier.sections variable. You can even add new sections that
|
||||||
|
describe application-specific data--just add the section's name to the list
|
||||||
|
(whereever you'd like), and define the corresponding partial. Then, if your
|
||||||
|
new section requires information that isn't available by default, make sure
|
||||||
|
it is made available to the email using the exception_data macro:
|
||||||
|
|
||||||
|
class ApplicationController < ActionController::Base
|
||||||
|
before_filter :log_additional_data
|
||||||
|
...
|
||||||
|
protected
|
||||||
|
def log_additional_data
|
||||||
|
request.env["exception_notifier.exception_data"] = {
|
||||||
|
:document => @document,
|
||||||
|
:person => @person
|
||||||
|
}
|
||||||
|
end
|
||||||
|
...
|
||||||
|
end
|
||||||
|
|
||||||
|
In the above case, @document and @person would be made available to the email
|
||||||
|
renderer, allowing your new section(s) to access and display them. See the
|
||||||
|
existing sections defined by the plugin for examples of how to write your own.
|
||||||
|
|
||||||
|
== Notification
|
||||||
|
|
||||||
|
After an exception notification has been delivered the rack environment variable
|
||||||
|
'exception_notifier.delivered' will be set to +true+.
|
||||||
|
|
||||||
|
== Rails 2.3 stable and earlier
|
||||||
|
|
||||||
|
If you are running Rails 2.3 then see the branch for that:
|
||||||
|
|
||||||
|
http://github.com/rails/exception_notification/tree/2-3-stable
|
||||||
|
|
||||||
|
If you are running pre-rack Rails then see this tag:
|
||||||
|
|
||||||
|
http://github.com/rails/exception_notification/tree/pre-2-3
|
||||||
|
|
||||||
|
== Support and tickets
|
||||||
|
|
||||||
|
https://rails.lighthouseapp.com/projects/8995-rails-plugins
|
||||||
|
|
||||||
|
Copyright (c) 2005 Jamis Buck, released under the MIT license
|
||||||
11
vendor/plugins/exception_notification/exception_notification.gemspec
vendored
Normal file
11
vendor/plugins/exception_notification/exception_notification.gemspec
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = 'exception_notification'
|
||||||
|
s.version = '1.0.0'
|
||||||
|
s.authors = ["Jamis Buck", "Josh Peek"]
|
||||||
|
s.date = %q{2010-03-13}
|
||||||
|
s.summary = "Exception notification by email for Rails apps"
|
||||||
|
s.email = "timocratic@gmail.com"
|
||||||
|
|
||||||
|
s.files = ['README'] + Dir['lib/**/*']
|
||||||
|
s.require_path = 'lib'
|
||||||
|
end
|
||||||
31
vendor/plugins/exception_notification/lib/exception_notifier.rb
vendored
Normal file
31
vendor/plugins/exception_notification/lib/exception_notifier.rb
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
require 'action_dispatch'
|
||||||
|
require 'exception_notifier/notifier'
|
||||||
|
|
||||||
|
class ExceptionNotifier
|
||||||
|
def self.default_ignore_exceptions
|
||||||
|
[].tap do |exceptions|
|
||||||
|
exceptions << ActiveRecord::RecordNotFound if defined? ActiveRecord
|
||||||
|
exceptions << AbstractController::ActionNotFound if defined? AbstractController
|
||||||
|
exceptions << ActionController::RoutingError if defined? ActionController
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(app, options = {})
|
||||||
|
@app, @options = app, options
|
||||||
|
@options[:ignore_exceptions] ||= self.class.default_ignore_exceptions
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
@app.call(env)
|
||||||
|
rescue Exception => exception
|
||||||
|
options = (env['exception_notifier.options'] ||= {})
|
||||||
|
options.reverse_merge!(@options)
|
||||||
|
|
||||||
|
unless Array.wrap(options[:ignore_exceptions]).include?(exception.class)
|
||||||
|
Notifier.exception_notification(env, exception).deliver
|
||||||
|
env['exception_notifier.delivered'] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
raise exception
|
||||||
|
end
|
||||||
|
end
|
||||||
83
vendor/plugins/exception_notification/lib/exception_notifier/notifier.rb
vendored
Normal file
83
vendor/plugins/exception_notification/lib/exception_notifier/notifier.rb
vendored
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
require 'action_mailer'
|
||||||
|
require 'pp'
|
||||||
|
|
||||||
|
class ExceptionNotifier
|
||||||
|
class Notifier < ActionMailer::Base
|
||||||
|
self.mailer_name = 'exception_notifier'
|
||||||
|
self.append_view_path "#{File.dirname(__FILE__)}/views"
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def default_sender_address
|
||||||
|
%("Exception Notifier" <exception.notifier@default.com>)
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_exception_recipients
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_email_prefix
|
||||||
|
"[ERROR] "
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_sections
|
||||||
|
%w(request session environment backtrace)
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_options
|
||||||
|
{ :sender_address => default_sender_address,
|
||||||
|
:exception_recipients => default_exception_recipients,
|
||||||
|
:email_prefix => default_email_prefix,
|
||||||
|
:sections => default_sections }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class MissingController
|
||||||
|
def method_missing(*args, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def exception_notification(env, exception)
|
||||||
|
@env = env
|
||||||
|
@exception = exception
|
||||||
|
@options = (env['exception_notifier.options'] || {}).reverse_merge(self.class.default_options)
|
||||||
|
@kontroller = env['action_controller.instance'] || MissingController.new
|
||||||
|
@request = ActionDispatch::Request.new(env)
|
||||||
|
@backtrace = clean_backtrace(exception)
|
||||||
|
@sections = @options[:sections]
|
||||||
|
data = env['exception_notifier.exception_data'] || {}
|
||||||
|
|
||||||
|
data.each do |name, value|
|
||||||
|
instance_variable_set("@#{name}", value)
|
||||||
|
end
|
||||||
|
|
||||||
|
prefix = "#{@options[:email_prefix]}#{@kontroller.controller_name}##{@kontroller.action_name}"
|
||||||
|
subject = "#{prefix} (#{@exception.class}) #{@exception.message.inspect}"
|
||||||
|
|
||||||
|
mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
|
||||||
|
format.text { render "#{mailer_name}/exception_notification" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def clean_backtrace(exception)
|
||||||
|
Rails.respond_to?(:backtrace_cleaner) ?
|
||||||
|
Rails.backtrace_cleaner.send(:filter, exception.backtrace) :
|
||||||
|
exception.backtrace
|
||||||
|
end
|
||||||
|
|
||||||
|
helper_method :inspect_object
|
||||||
|
|
||||||
|
def inspect_object(object)
|
||||||
|
case object
|
||||||
|
when Hash, Array
|
||||||
|
object.inspect
|
||||||
|
when ActionController::Base
|
||||||
|
"#{object.controller_name}##{object.action_name}"
|
||||||
|
else
|
||||||
|
object.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<%= raw @backtrace.join("\n") %>
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
<% filtered_env = @request.filtered_env -%>
|
||||||
|
<% max = filtered_env.keys.max { |a, b| a.length <=> b.length } -%>
|
||||||
|
<% filtered_env.keys.sort.each do |key| -%>
|
||||||
|
* <%= raw("%-*s: %s" % [max.length, key, inspect_object(filtered_env[key])]) %>
|
||||||
|
<% end -%>
|
||||||
|
|
||||||
|
* Process: <%= raw $$ %>
|
||||||
|
* Server : <%= raw `hostname -s`.chomp %>
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
* URL : <%= raw @request.url %>
|
||||||
|
* IP address: <%= raw @request.remote_ip %>
|
||||||
|
* Parameters: <%= raw @request.filtered_parameters.inspect %>
|
||||||
|
* Rails root: <%= raw Rails.root %>
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
* session id: <%= raw @request.session['session_id'].inspect.html_safe %>
|
||||||
|
* data: <%= raw PP.pp(@request.session, "") %>
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
-------------------------------
|
||||||
|
<%= raw title.to_s.humanize %>:
|
||||||
|
-------------------------------
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
A <%= @exception.class %> occurred in <%= @kontroller.controller_name %>#<%= @kontroller.action_name %>:
|
||||||
|
|
||||||
|
<%= raw @exception.message %>
|
||||||
|
<%= raw @backtrace.first %>
|
||||||
|
|
||||||
|
<% sections = @sections.map do |section|
|
||||||
|
summary = render(section).strip
|
||||||
|
unless summary.blank?
|
||||||
|
title = render("title", :title => section).strip
|
||||||
|
"#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
|
||||||
|
end
|
||||||
|
end %>
|
||||||
|
<%= raw sections.join %>
|
||||||
Loading…
Reference in New Issue
Block a user