whoops_rails_logger 0.1.0

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/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = WhoopsRailsLogger
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
18
+
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'WhoopsRailsLogger'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README.rdoc')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
@@ -0,0 +1,19 @@
1
+ module WhoopsRailsLogger
2
+ module ActionControllerCatcher
3
+ # Sets up an alias chain to catch exceptions when Rails does
4
+ def self.included(base) #:nodoc:
5
+ # base.send(:alias_method, :rescue_action_in_public_without_whoops, :rescue_action_in_public)
6
+ # base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_whoops)
7
+ end
8
+
9
+ private
10
+
11
+ # Overrides the rescue_action method in ActionController::Base, but does not inhibit
12
+ # any custom processing that is defined with Rails 2's exception helpers.
13
+ def rescue_action_in_public_with_whoops(exception)
14
+ raw_data = {:exception => exception}.merge(whoops_request_data)
15
+ WhoopsRailsLogger.notify(raw_data)
16
+ rescue_action_in_public_without_whoops(exception)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,50 @@
1
+ module WhoopsRailsLogger
2
+ module ControllerMethods
3
+ private
4
+
5
+ # This method should be used for sending manual notifications while you are still
6
+ # inside the controller. Otherwise it works like WhoopsLoggerRails.notify.
7
+ def notify_whoops(exception)
8
+ raw_data = {:exception => exception}.merge(whoops_request_data)
9
+ WhoopsRailsLogger.notify(:rails, raw_data)
10
+ end
11
+
12
+ def whoops_request_data
13
+ { :parameters => whoops_filter_if_filtering(params.to_hash),
14
+ :session_data => whoops_filter_if_filtering(whoops_session_data),
15
+ :controller => params[:controller],
16
+ :action => params[:action],
17
+ :url => whoops_request_url,
18
+ :cgi_data => whoops_filter_if_filtering(request.env) }
19
+ end
20
+
21
+ def whoops_filter_if_filtering(hash)
22
+ return hash if ! hash.is_a?(Hash)
23
+
24
+ if respond_to?(:filter_parameters)
25
+ filter_parameters(hash) rescue hash
26
+ else
27
+ hash
28
+ end
29
+ end
30
+
31
+ def whoops_session_data
32
+ if session.respond_to?(:to_hash)
33
+ session.to_hash
34
+ else
35
+ session.data
36
+ end
37
+ end
38
+
39
+ def whoops_request_url
40
+ url = "#{request.protocol}#{request.host}"
41
+
42
+ unless [80, 443].include?(request.port)
43
+ url << ":#{request.port}"
44
+ end
45
+
46
+ url << request.request_uri
47
+ url
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ module WhoopsRailsLogger
2
+ class Evidence
3
+ attr_accessor :exception
4
+ attr_accessor :url
5
+
6
+ def initialize(exception, rack)
7
+ self.exception = exception
8
+ self.rack = rack
9
+ self.url = args[:url] || rack_env(:url)
10
+
11
+ self.parameters = args[:parameters] ||
12
+ action_dispatch_params ||
13
+ rack_env(:params) ||
14
+ {}
15
+ self.component = args[:component] || args[:controller] || parameters['controller']
16
+ self.action = args[:action] || parameters['action']
17
+
18
+ self.environment_name = args[:environment_name]
19
+ self.cgi_data = args[:cgi_data] || args[:rack_env]
20
+ self.backtrace = Backtrace.parse(exception_attribute(:backtrace, caller), :filters => self.backtrace_filters)
21
+ self.error_class = exception_attribute(:error_class) {|exception| exception.class.name }
22
+ self.error_message = exception_attribute(:error_message, 'Notification') do |exception|
23
+ end
24
+
25
+ def action_dispatch_params
26
+ rack[:rack_env]['action_dispatch.request.parameters'] if rack
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ module WhoopsRailsLogger
2
+ class ExceptionStrategy < WhoopsLogger::Strategy
3
+ attr_accessor :service, :environment
4
+ def initialize(strategy_name)
5
+ super
6
+
7
+ self.service = ::Rails.application.class.name.split("::").first.downcase + ".web"
8
+ self.environment = ::Rails.env
9
+
10
+ add_message_builders
11
+ end
12
+
13
+ def add_message_builders
14
+ self.add_message_builder(:basic_details) do |message, raw_data|
15
+ message.service = self.service
16
+ message.environment = self.environment
17
+ message.event_type = "exception"
18
+ message.message = raw_data[:exception].message
19
+ message.event_time = Time.now
20
+ end
21
+
22
+ self.add_message_builder(:details) do |message, raw_data|
23
+ exception = raw_data[:exception]
24
+ rack_env = raw_data[:rack_env]
25
+
26
+ details = {}
27
+ details[:backtrace] = exception.backtrace.collect{ |line|
28
+ line.sub(/^#{ENV['GEM_HOME']}/, '$GEM_HOME').sub(/^#{Rails.root}/, '$Rails.root')
29
+ }
30
+ details[:params] = rack_env["action_dispatch.request.parameters"]
31
+ message.details = details
32
+ end
33
+
34
+ self.add_message_builder(:create_event_group_identifier) do |message, raw_data|
35
+ identifier = "#{raw_data[:controller]}##{raw_data[:action]}"
36
+ identifier << raw_data[:exception].backtrace.collect{|l| l.sub(Rails.root, "")}.join("\n")
37
+ message.event_group_identifier = Digest::MD5.hexdigest(identifier)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module WhoopsRailsLogger
2
+ # Middleware for Rack applications. Any errors raised by the upstream
3
+ # application will be delivered to whoops and re-raised.
4
+ class Rack
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ begin
11
+ response = @app.call(env)
12
+ rescue Exception => raised
13
+ raw_data = {
14
+ :exception => raised,
15
+ :rack_env => env
16
+ }
17
+ WhoopsLogger.notify(:rails_exception, raw_data)
18
+ raise
19
+ end
20
+
21
+ response
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module WhoopsRailsLogger
2
+ class Railtie < Rails::Railtie
3
+ # config.app_middleware.insert_after "ActionDispatch::Callbacks"
4
+ config.app_middleware.use WhoopsRailsLogger::Rack
5
+
6
+ config.after_initialize do
7
+ WhoopsRailsLogger.initialize
8
+ ::ActionController::Base.send(:include, WhoopsRailsLogger::ControllerMethods)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ require "digest"
2
+ require "whoops_logger"
3
+ require "whoops_rails_logger/action_controller_catcher"
4
+ require "whoops_rails_logger/controller_methods"
5
+ require "whoops_rails_logger/exception_strategy"
6
+ require "whoops_rails_logger/rack"
7
+ require "whoops_rails_logger/railtie"
8
+
9
+ module WhoopsRailsLogger
10
+ def self.initialize
11
+ configure
12
+ create_exception_strategy
13
+ end
14
+
15
+ def self.configure
16
+ config = YAML.load_file(File.join(Rails.root, "config", "whoops.yml"))[Rails.env]
17
+ WhoopsLogger.config.set(config)
18
+ WhoopsLogger.config.logger = Rails.logger
19
+ end
20
+
21
+ def self.create_exception_strategy
22
+ strategy = WhoopsRailsLogger::ExceptionStrategy.new(:rails_exception)
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whoops_rails_logger
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Daniel Higginbotham
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-12 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: whoops_logger
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 0
34
+ version: 0.1.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rails
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 5
46
+ segments:
47
+ - 3
48
+ version: "3"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rake
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - "="
58
+ - !ruby/object:Gem::Version
59
+ hash: 49
60
+ segments:
61
+ - 0
62
+ - 8
63
+ - 7
64
+ version: 0.8.7
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec-rails
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: ruby-debug
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: fakeweb
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: sqlite3
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ type: :development
122
+ version_requirements: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ name: capybara
125
+ prerelease: false
126
+ requirement: &id008 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 15
132
+ segments:
133
+ - 0
134
+ - 4
135
+ - 0
136
+ version: 0.4.0
137
+ type: :development
138
+ version_requirements: *id008
139
+ description: A Whoops Logger for Rails 3 apps.
140
+ email:
141
+ executables: []
142
+
143
+ extensions: []
144
+
145
+ extra_rdoc_files: []
146
+
147
+ files:
148
+ - lib/whoops_rails_logger/action_controller_catcher.rb
149
+ - lib/whoops_rails_logger/controller_methods.rb
150
+ - lib/whoops_rails_logger/evidence.rb
151
+ - lib/whoops_rails_logger/exception_strategy.rb
152
+ - lib/whoops_rails_logger/rack.rb
153
+ - lib/whoops_rails_logger/railtie.rb
154
+ - lib/whoops_rails_logger.rb
155
+ - MIT-LICENSE
156
+ - Rakefile
157
+ - Gemfile
158
+ - README.rdoc
159
+ has_rdoc: true
160
+ homepage:
161
+ licenses: []
162
+
163
+ post_install_message:
164
+ rdoc_options: []
165
+
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ hash: 3
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ hash: 3
183
+ segments:
184
+ - 0
185
+ version: "0"
186
+ requirements: []
187
+
188
+ rubyforge_project:
189
+ rubygems_version: 1.3.7
190
+ signing_key:
191
+ specification_version: 3
192
+ summary: A Whoops Logger for Rails 3 apps.
193
+ test_files: []
194
+