rails_exception_log 1.0.0 → 1.0.2
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.
- checksums.yaml +4 -4
- data/app/controllers/rails_exception_log/logged_exceptions_controller.rb +14 -8
- data/app/helpers/rails_exception_log/application_helper.rb +6 -0
- data/config/routes.rb +11 -15
- data/lib/rails_exception_log/engine.rb +4 -5
- data/lib/rails_exception_log/exception_loggable.rb +24 -71
- data/lib/rails_exception_log/version.rb +1 -1
- data/lib/rails_exception_log.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c4183a841770842781604680724d9cd98c892263c4ac37803d9700e4d5351cb1
|
|
4
|
+
data.tar.gz: 563e8d0a60e595bec9c426363ea844c2fd1e2fd17cbd32a127b804ad3ac76a02
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be9ce4604010b52163e5eadf4d3b743fb1b69e168e49af1b1d13f7739811b5e084479ad00c07a0ea4bd692ef967e0c6d5d147b559158493417081b61141cbd5a
|
|
7
|
+
data.tar.gz: fca6c0ac8e54c8f02b7b266512129bc731bc447b324bc28874cbf07ec8124f72b7c359edac8d1f283754ad6791d8df8ba88530fe5dd3688e81da034fb4ac3251
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
require 'csv'
|
|
2
|
-
|
|
3
1
|
module RailsExceptionLog
|
|
4
2
|
class LoggedExceptionsController < ApplicationController
|
|
5
3
|
before_action :load_exception, only: %i[show destroy resolve reopen ignore add_comment]
|
|
6
4
|
|
|
7
5
|
def index
|
|
6
|
+
page = params[:page].to_i.positive? ? params[:page].to_i : 1
|
|
7
|
+
per_page = 25
|
|
8
|
+
|
|
8
9
|
@exceptions = filtered_exceptions
|
|
9
10
|
.select(:id, :exception_class, :message, :controller_name,
|
|
10
11
|
:action_name, :request_method, :request_path,
|
|
11
12
|
:environment, :created_at, :status, :occurrence_count,
|
|
12
13
|
:last_occurred_at, :resolved_at)
|
|
13
14
|
.order(last_occurred_at: :desc)
|
|
14
|
-
.
|
|
15
|
+
.limit(per_page)
|
|
16
|
+
.offset((page - 1) * per_page)
|
|
17
|
+
|
|
18
|
+
total_count = filtered_exceptions.count
|
|
19
|
+
@total_pages = (total_count.to_f / per_page).ceil
|
|
15
20
|
|
|
16
21
|
@exception_classes = RailsExceptionLog::LoggedException
|
|
17
22
|
.select(:exception_class)
|
|
@@ -60,25 +65,25 @@ module RailsExceptionLog
|
|
|
60
65
|
|
|
61
66
|
def resolve
|
|
62
67
|
@exception.mark_resolved!
|
|
63
|
-
redirect_to
|
|
68
|
+
redirect_to railsexceptionlog_exceptions_path,
|
|
64
69
|
notice: 'Exception marked as resolved'
|
|
65
70
|
end
|
|
66
71
|
|
|
67
72
|
def reopen
|
|
68
73
|
@exception.mark_open!
|
|
69
|
-
redirect_to
|
|
74
|
+
redirect_to railsexceptionlog_exceptions_path,
|
|
70
75
|
notice: 'Exception reopened'
|
|
71
76
|
end
|
|
72
77
|
|
|
73
78
|
def ignore
|
|
74
79
|
@exception.update!(status: :ignored)
|
|
75
|
-
redirect_to
|
|
80
|
+
redirect_to railsexceptionlog_exceptions_path,
|
|
76
81
|
notice: 'Exception ignored'
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
def add_comment
|
|
80
85
|
@exception.add_comment!(params[:comment], author: current_user_email)
|
|
81
|
-
redirect_to
|
|
86
|
+
redirect_to railsexceptionlog_exceptions_path,
|
|
82
87
|
notice: 'Comment added'
|
|
83
88
|
end
|
|
84
89
|
|
|
@@ -129,6 +134,8 @@ module RailsExceptionLog
|
|
|
129
134
|
end
|
|
130
135
|
|
|
131
136
|
def export_to_csv(exceptions)
|
|
137
|
+
require 'csv'
|
|
138
|
+
|
|
132
139
|
CSV.generate(headers: true) do |csv|
|
|
133
140
|
csv << ['ID', 'Exception Class', 'Message', 'Controller', 'Action', 'Path', 'Method', 'Environment', 'Status',
|
|
134
141
|
'Occurrences', 'Created At']
|
|
@@ -151,7 +158,6 @@ module RailsExceptionLog
|
|
|
151
158
|
end
|
|
152
159
|
|
|
153
160
|
def current_user_email
|
|
154
|
-
# Override this method to return the current user's email
|
|
155
161
|
'anonymous'
|
|
156
162
|
end
|
|
157
163
|
end
|
data/config/routes.rb
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
delete '/exceptions', to: 'logged_exceptions#destroy_all'
|
|
8
|
-
get '/exceptions/export', to: 'logged_exceptions#export'
|
|
1
|
+
RailsExceptionLog::Engine.routes.draw do
|
|
2
|
+
get '/', to: 'logged_exceptions#index', as: :railsexceptionlog_exceptions
|
|
3
|
+
get '/:id', to: 'logged_exceptions#show', as: :railsexceptionlog_exception
|
|
4
|
+
delete '/:id', to: 'logged_exceptions#destroy'
|
|
5
|
+
delete '/', to: 'logged_exceptions#destroy_all'
|
|
6
|
+
get '/export', to: 'logged_exceptions#export'
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
end
|
|
8
|
+
post '/:id/resolve', to: 'logged_exceptions#resolve', as: :resolve_railsexceptionlog_exception
|
|
9
|
+
post '/:id/reopen', to: 'logged_exceptions#reopen', as: :reopen_railsexceptionlog_exception
|
|
10
|
+
post '/:id/ignore', to: 'logged_exceptions#ignore', as: :ignore_railsexceptionlog_exception
|
|
11
|
+
post '/:id/add_comment', to: 'logged_exceptions#add_comment',
|
|
12
|
+
as: :add_comment_railsexceptionlog_exception
|
|
17
13
|
end
|
|
@@ -4,17 +4,16 @@ module RailsExceptionLog
|
|
|
4
4
|
class Engine < ::Rails::Engine
|
|
5
5
|
isolate_namespace RailsExceptionLog
|
|
6
6
|
|
|
7
|
+
config.eager_load_paths << root.join('app/helpers')
|
|
8
|
+
|
|
7
9
|
initializer 'rails_exception_log.assets' do |app|
|
|
8
10
|
app.config.assets.paths << root.join('app/assets/stylesheets') if defined?(Sprockets) && app.config.assets
|
|
9
|
-
|
|
10
|
-
if defined?(Propshaft)
|
|
11
|
-
app.config.assets.loader = 'bun'
|
|
12
|
-
app.config.assets.build_paths << root.join('app/assets/builds')
|
|
13
|
-
end
|
|
14
11
|
end
|
|
15
12
|
|
|
16
13
|
initializer 'rails_exception_log.helpers' do
|
|
17
14
|
ActionView::Base.include RailsExceptionLog::ApplicationHelper
|
|
15
|
+
rescue NameError, LoadError
|
|
16
|
+
# Helper may not be available
|
|
18
17
|
end
|
|
19
18
|
|
|
20
19
|
config.after_initialize do
|
|
@@ -4,86 +4,39 @@ module RailsExceptionLog
|
|
|
4
4
|
module ExceptionLoggable
|
|
5
5
|
extend ActiveSupport::Concern
|
|
6
6
|
|
|
7
|
-
included do
|
|
8
|
-
after_action :log_exception_to_db, if: :exception_loggable?
|
|
9
|
-
end
|
|
10
|
-
|
|
11
7
|
def log_exception_handler
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
Rails.logger.info '=' * 50
|
|
9
|
+
Rails.logger.info 'RAILS_EXCEPTION_LOG: Handler triggered!'
|
|
10
|
+
Rails.logger.info "Exception: #{exception.inspect}"
|
|
11
|
+
Rails.logger.info '=' * 50
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
return false if is_a?(RailsExceptionLog::LoggedExceptionsController)
|
|
21
|
-
return false if ENV['RAILS_EXCEPTION_LOG_DISABLED'] == 'true'
|
|
22
|
-
return false unless rate_limit_allow?
|
|
23
|
-
|
|
24
|
-
true
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def rate_limit_allow?
|
|
28
|
-
return true if Rails.env.development?
|
|
29
|
-
|
|
30
|
-
key = "exception_log_rate_limit:#{request&.remote_ip}"
|
|
31
|
-
count = Rails.cache.fetch(key, expires_in: 1.minute) do
|
|
32
|
-
0
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
max = RailsExceptionLog.max_requests_per_minute || 60
|
|
36
|
-
return false if count >= max
|
|
37
|
-
|
|
38
|
-
Rails.cache.write(key, count + 1, expires_in: 1.minute)
|
|
39
|
-
true
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def log_exception_to_db
|
|
43
|
-
return unless exception || defined?(@exception) && @exception
|
|
44
|
-
|
|
45
|
-
exc = exception || @exception
|
|
46
|
-
return unless exc
|
|
13
|
+
exc = exception
|
|
14
|
+
return raise exc unless exc.present?
|
|
15
|
+
return raise exc if is_a?(RailsExceptionLog::LoggedExceptionsController)
|
|
16
|
+
return raise exc if ENV['RAILS_EXCEPTION_LOG_DISABLED'] == 'true'
|
|
47
17
|
|
|
48
18
|
begin
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
logged_exception = RailsExceptionLog::LoggedException.
|
|
52
|
-
exc,
|
|
53
|
-
|
|
54
|
-
|
|
19
|
+
current_user if respond_to?(:current_user)
|
|
20
|
+
|
|
21
|
+
logged_exception = RailsExceptionLog::LoggedException.create!(
|
|
22
|
+
exception_class: exc.class.name,
|
|
23
|
+
message: exc.message,
|
|
24
|
+
backtrace: exc.backtrace&.join("\n"),
|
|
25
|
+
controller_name: controller_name,
|
|
26
|
+
action_name: action_name,
|
|
27
|
+
request_method: request&.method&.to_s,
|
|
28
|
+
request_path: request&.path,
|
|
29
|
+
request_params: request&.parameters&.to_h,
|
|
30
|
+
environment: Rails.env,
|
|
31
|
+
last_occurred_at: Time.current
|
|
55
32
|
)
|
|
56
33
|
|
|
57
|
-
|
|
58
|
-
data = exception_data.is_a?(Proc) ? instance_exec(self, &exception_data) : send(exception_data)
|
|
59
|
-
logged_exception.update!(exception_data: data) if data.present?
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
RailsExceptionLog.after_log_exception.call(logged_exception) if RailsExceptionLog.after_log_exception
|
|
34
|
+
Rails.logger.info "RAILS_EXCEPTION_LOG: Created #{logged_exception.id}"
|
|
63
35
|
rescue StandardError => e
|
|
64
|
-
Rails.logger.error "
|
|
36
|
+
Rails.logger.error "RAILS_EXCEPTION_LOG Error: #{e.message}"
|
|
65
37
|
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def request_params_without_passwords
|
|
69
|
-
return {} unless request&.params
|
|
70
38
|
|
|
71
|
-
|
|
72
|
-
filter_passwords(params_hash)
|
|
73
|
-
params_hash
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def filter_passwords(hash)
|
|
77
|
-
hash.each do |key, value|
|
|
78
|
-
if key.to_s =~ /password|secret|token/i
|
|
79
|
-
hash[key] = '[FILTERED]'
|
|
80
|
-
elsif value.is_a?(Hash)
|
|
81
|
-
filter_passwords(value)
|
|
82
|
-
elsif value.is_a?(Array)
|
|
83
|
-
value.each { |v| filter_passwords(v) if v.is_a?(Hash) }
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
hash
|
|
39
|
+
raise exc
|
|
87
40
|
end
|
|
88
41
|
end
|
|
89
42
|
end
|
data/lib/rails_exception_log.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'rails_exception_log/engine'
|
|
2
2
|
require 'rails_exception_log/version'
|
|
3
|
+
require 'rails_exception_log/exception_loggable'
|
|
3
4
|
|
|
4
5
|
module RailsExceptionLog
|
|
5
6
|
mattr_accessor :application_name, default: 'Rails Exception Log'
|
|
@@ -21,3 +22,7 @@ module RailsExceptionLog
|
|
|
21
22
|
yield self
|
|
22
23
|
end
|
|
23
24
|
end
|
|
25
|
+
|
|
26
|
+
ActiveSupport.on_load(:action_controller_base) do
|
|
27
|
+
include RailsExceptionLog::ExceptionLoggable
|
|
28
|
+
end
|