Browse Source

monkey_patcher

pagy
pvincent 1 month ago
parent
commit
2e77009d53
  1. 1
      Gemfile
  2. 7
      Gemfile.lock
  3. 15
      config/initializers/monkey_patcher.rb
  4. 14
      lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb

1
Gemfile

@ -29,7 +29,6 @@ group :development do
gem 'rubocop-shopify'
gem 'rubocop-thread_safety'
gem 'ruby-lsp-rails'
gem 'web-console'
end
group :test do

7
Gemfile.lock

@ -81,7 +81,6 @@ GEM
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.7)
bindex (0.8.1)
bootsnap (1.18.3)
msgpack (~> 1.2)
builder (3.2.4)
@ -313,11 +312,6 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webrick (1.8.1)
websocket (1.2.10)
websocket-driver (0.7.6)
@ -363,7 +357,6 @@ DEPENDENCIES
stimulus-rails
tailwindcss-rails
turbo-rails
web-console
RUBY VERSION
ruby 3.1.2p20

15
config/initializers/monkey_patcher.rb

@ -0,0 +1,15 @@
return unless defined?(Rails::Server)
logger = SemanticLogger['MonkeyPatcher']
patches = Dir.glob(Rails.root.join('lib', 'monkey_patches', '**', '*.rb'))
patches.each do |file|
logger.info "patching... #{Pathname.new(file).relative_path_from Rails.root}"
require file
end
case patches.count
when 0 then logger.info '== No patch found =='
when 1 then logger.info '== 1 successful patch applied =='
else logger.info "== #{count} successful patch applied =="
end

14
lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb

@ -0,0 +1,14 @@
require 'rails_semantic_logger/extensions/action_dispatch/debug_exceptions'
module ActionDispatch
# patched class to prevent deprecated message
class DebugExceptions
private
def log_error(_request, wrapper)
Rails.application.deprecators.silence do
ActionController::Base.logger.fatal(wrapper.exception)
end
end
end
end
Loading…
Cancel
Save