rails_exception_log 1.0.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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +173 -0
- data/app/assets/config/tailwind.config.js +34 -0
- data/app/assets/stylesheets/rails_exception_log/application.css +12 -0
- data/app/controllers/rails_exception_log/application_controller.rb +17 -0
- data/app/controllers/rails_exception_log/logged_exceptions_controller.rb +158 -0
- data/app/helpers/rails_exception_log/application_helper.rb +52 -0
- data/app/javascript/controllers/dropdown_controller.js +22 -0
- data/app/javascript/index.js +4 -0
- data/app/models/rails_exception_log/logged_exception.rb +149 -0
- data/app/views/rails_exception_log/logged_exceptions/index.html.erb +278 -0
- data/app/views/rails_exception_log/logged_exceptions/show.html.erb +214 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20240101000000_create_rails_exception_log_logged_exceptions.rb +36 -0
- data/lib/generators/rails_exception_log/install_generator.rb +54 -0
- data/lib/rails_exception_log/engine.rb +26 -0
- data/lib/rails_exception_log/exception_loggable.rb +89 -0
- data/lib/rails_exception_log/version.rb +3 -0
- data/lib/rails_exception_log.rb +23 -0
- metadata +127 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'digest'
|
|
2
|
+
|
|
3
|
+
module RailsExceptionLog
|
|
4
|
+
module ExceptionLoggable
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
after_action :log_exception_to_db, if: :exception_loggable?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def log_exception_handler
|
|
12
|
+
log_exception_to_db
|
|
13
|
+
raise exception
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def exception_loggable?
|
|
19
|
+
return false if exception.nil?
|
|
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
|
|
47
|
+
|
|
48
|
+
begin
|
|
49
|
+
user = current_user if respond_to?(:current_user)
|
|
50
|
+
|
|
51
|
+
logged_exception = RailsExceptionLog::LoggedException.create_or_update_with_fingerprint!(
|
|
52
|
+
exc,
|
|
53
|
+
request,
|
|
54
|
+
user: user
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
if respond_to?(:exception_data)
|
|
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
|
|
63
|
+
rescue StandardError => e
|
|
64
|
+
Rails.logger.error "Failed to log exception: #{e.message}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def request_params_without_passwords
|
|
69
|
+
return {} unless request&.params
|
|
70
|
+
|
|
71
|
+
params_hash = request.params.deep_dup
|
|
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
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'rails_exception_log/engine'
|
|
2
|
+
require 'rails_exception_log/version'
|
|
3
|
+
|
|
4
|
+
module RailsExceptionLog
|
|
5
|
+
mattr_accessor :application_name, default: 'Rails Exception Log'
|
|
6
|
+
|
|
7
|
+
mattr_accessor :before_log_exception do |_controller|
|
|
8
|
+
true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
mattr_accessor :after_log_exception do |logged_exception|
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
mattr_accessor :max_requests_per_minute, default: 60
|
|
15
|
+
|
|
16
|
+
mattr_accessor :enable_user_tracking, default: true
|
|
17
|
+
|
|
18
|
+
mattr_accessor :filter_parameters, default: %i[password secret token api_key]
|
|
19
|
+
|
|
20
|
+
def self.configure
|
|
21
|
+
yield self
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rails_exception_log
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "Tamiru Hailu\n "
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '9.0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '7.0'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '9.0'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: mysql2
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0.5'
|
|
39
|
+
type: :development
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0.5'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: pg
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '1.0'
|
|
53
|
+
type: :development
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '1.0'
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: sqlite3
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - "~>"
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '1.4'
|
|
67
|
+
type: :development
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - "~>"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '1.4'
|
|
74
|
+
description: A beautiful exception logging gem that stores Rails exceptions in a database
|
|
75
|
+
with a modern Tailwind UI dashboard
|
|
76
|
+
email:
|
|
77
|
+
- tamiruhailu@gmail.com
|
|
78
|
+
executables: []
|
|
79
|
+
extensions: []
|
|
80
|
+
extra_rdoc_files: []
|
|
81
|
+
files:
|
|
82
|
+
- MIT-LICENSE
|
|
83
|
+
- README.md
|
|
84
|
+
- app/assets/config/tailwind.config.js
|
|
85
|
+
- app/assets/stylesheets/rails_exception_log/application.css
|
|
86
|
+
- app/controllers/rails_exception_log/application_controller.rb
|
|
87
|
+
- app/controllers/rails_exception_log/logged_exceptions_controller.rb
|
|
88
|
+
- app/helpers/rails_exception_log/application_helper.rb
|
|
89
|
+
- app/javascript/controllers/dropdown_controller.js
|
|
90
|
+
- app/javascript/index.js
|
|
91
|
+
- app/models/rails_exception_log/logged_exception.rb
|
|
92
|
+
- app/views/rails_exception_log/logged_exceptions/index.html.erb
|
|
93
|
+
- app/views/rails_exception_log/logged_exceptions/show.html.erb
|
|
94
|
+
- config/routes.rb
|
|
95
|
+
- db/migrate/20240101000000_create_rails_exception_log_logged_exceptions.rb
|
|
96
|
+
- lib/generators/rails_exception_log/install_generator.rb
|
|
97
|
+
- lib/rails_exception_log.rb
|
|
98
|
+
- lib/rails_exception_log/engine.rb
|
|
99
|
+
- lib/rails_exception_log/exception_loggable.rb
|
|
100
|
+
- lib/rails_exception_log/version.rb
|
|
101
|
+
homepage: https://github.com/tamiru/rails_exception_log
|
|
102
|
+
licenses:
|
|
103
|
+
- MIT
|
|
104
|
+
metadata:
|
|
105
|
+
bug_tracker_uri: https://github.com/yourusername/rails_exception_log/issues
|
|
106
|
+
changelog_uri: https://github.com/tamiru/rails_exception_log/blob/main/CHANGELOG.md
|
|
107
|
+
documentation_uri: https://github.com/tamiru/rails_exception_log#readme
|
|
108
|
+
homepage_uri: https://github.com/tamiru/rails_exception_log
|
|
109
|
+
source_code_uri: https://github.com/tamiru/rails_exception_log
|
|
110
|
+
rdoc_options: []
|
|
111
|
+
require_paths:
|
|
112
|
+
- lib
|
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '3.0'
|
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '0'
|
|
123
|
+
requirements: []
|
|
124
|
+
rubygems_version: 4.0.9
|
|
125
|
+
specification_version: 4
|
|
126
|
+
summary: Modern exception logging gem with Tailwind UI for Rails 7 and 8
|
|
127
|
+
test_files: []
|