rails_exception_log 1.0.0 → 1.0.1
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 +16 -10
- data/app/helpers/rails_exception_log/application_helper.rb +6 -0
- data/lib/rails_exception_log/engine.rb +18 -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 -2
- data/config/routes.rb +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1837d104081234ee91cf50d520158a47f3ada29bde03c70eab21b9fd87a3495b
|
|
4
|
+
data.tar.gz: bc817c81266b7955a3026df62cc88f56391c58d9ab087cc5c8dc71a56a473df8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb0f43621afbdc225e1db51822573e33c8bee27260cfc5f9546cfa0bc710c899bb052c8e0e47bd55ff93578d099485ce042478ab257d22e6e9dad17f880361cc
|
|
7
|
+
data.tar.gz: c11ac0b66730fa8741af48f007b197b604a3baae5535d5afd5363bc852d3c8af7af56c86320e69bb2844cadd1d5b8376808ca1c61de4761b8380ac537e3e6952
|
|
@@ -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)
|
|
@@ -54,31 +59,31 @@ module RailsExceptionLog
|
|
|
54
59
|
|
|
55
60
|
def destroy
|
|
56
61
|
@exception.destroy
|
|
57
|
-
redirect_to
|
|
62
|
+
redirect_to '/exceptions',
|
|
58
63
|
notice: 'Exception deleted successfully'
|
|
59
64
|
end
|
|
60
65
|
|
|
61
66
|
def resolve
|
|
62
67
|
@exception.mark_resolved!
|
|
63
|
-
redirect_to
|
|
68
|
+
redirect_to "/exceptions/#{@exception.id}",
|
|
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 "/exceptions/#{@exception.id}",
|
|
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 "/exceptions/#{@exception.id}",
|
|
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 "/exceptions/#{@exception.id}",
|
|
82
87
|
notice: 'Comment added'
|
|
83
88
|
end
|
|
84
89
|
|
|
@@ -88,7 +93,7 @@ module RailsExceptionLog
|
|
|
88
93
|
else
|
|
89
94
|
RailsExceptionLog::LoggedException.delete_all
|
|
90
95
|
end
|
|
91
|
-
redirect_to
|
|
96
|
+
redirect_to '/exceptions',
|
|
92
97
|
notice: 'Exceptions cleared'
|
|
93
98
|
end
|
|
94
99
|
|
|
@@ -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
|
|
@@ -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
|
|
@@ -24,3 +23,17 @@ module RailsExceptionLog
|
|
|
24
23
|
end
|
|
25
24
|
end
|
|
26
25
|
end
|
|
26
|
+
|
|
27
|
+
RailsExceptionLog::Engine.routes.draw do
|
|
28
|
+
get '/exceptions', to: 'logged_exceptions#index', as: :railsexceptionlog_exceptions
|
|
29
|
+
get '/exceptions/:id', to: 'logged_exceptions#show', as: :railsexceptionlog_exception
|
|
30
|
+
delete '/exceptions/:id', to: 'logged_exceptions#destroy'
|
|
31
|
+
delete '/exceptions', to: 'logged_exceptions#destroy_all'
|
|
32
|
+
get '/exceptions/export', to: 'logged_exceptions#export'
|
|
33
|
+
|
|
34
|
+
post '/exceptions/:id/resolve', to: 'logged_exceptions#resolve', as: :resolve_railsexceptionlog_exception
|
|
35
|
+
post '/exceptions/:id/reopen', to: 'logged_exceptions#reopen', as: :reopen_railsexceptionlog_exception
|
|
36
|
+
post '/exceptions/:id/ignore', to: 'logged_exceptions#ignore', as: :ignore_railsexceptionlog_exception
|
|
37
|
+
post '/exceptions/:id/add_comment', to: 'logged_exceptions#add_comment',
|
|
38
|
+
as: :add_comment_railsexceptionlog_exception
|
|
39
|
+
end
|
|
@@ -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
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_exception_log
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "Tamiru Hailu\n "
|
|
@@ -91,7 +91,6 @@ files:
|
|
|
91
91
|
- app/models/rails_exception_log/logged_exception.rb
|
|
92
92
|
- app/views/rails_exception_log/logged_exceptions/index.html.erb
|
|
93
93
|
- app/views/rails_exception_log/logged_exceptions/show.html.erb
|
|
94
|
-
- config/routes.rb
|
|
95
94
|
- db/migrate/20240101000000_create_rails_exception_log_logged_exceptions.rb
|
|
96
95
|
- lib/generators/rails_exception_log/install_generator.rb
|
|
97
96
|
- lib/rails_exception_log.rb
|
data/config/routes.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module RailsExceptionLog
|
|
2
|
-
module Routes
|
|
3
|
-
def draw
|
|
4
|
-
get '/exceptions', to: 'logged_exceptions#index', as: :railsexceptionlog_exceptions
|
|
5
|
-
get '/exceptions/:id', to: 'logged_exceptions#show', as: :railsexceptionlog_exception
|
|
6
|
-
delete '/exceptions/:id', to: 'logged_exceptions#destroy'
|
|
7
|
-
delete '/exceptions', to: 'logged_exceptions#destroy_all'
|
|
8
|
-
get '/exceptions/export', to: 'logged_exceptions#export'
|
|
9
|
-
|
|
10
|
-
post '/exceptions/:id/resolve', to: 'logged_exceptions#resolve', as: :resolve_railsexceptionlog_exception
|
|
11
|
-
post '/exceptions/:id/reopen', to: 'logged_exceptions#reopen', as: :reopen_railsexceptionlog_exception
|
|
12
|
-
post '/exceptions/:id/ignore', to: 'logged_exceptions#ignore', as: :ignore_railsexceptionlog_exception
|
|
13
|
-
post '/exceptions/:id/add_comment', to: 'logged_exceptions#add_comment',
|
|
14
|
-
as: :add_comment_railsexceptionlog_exception
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|