File tree Expand file tree Collapse file tree 5 files changed +39
-4
lines changed
lib/rails_semantic_logger/extensions/action_dispatch Expand file tree Collapse file tree 5 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,17 @@ class DebugExceptions
66 private
77
88 undef_method :log_error
9- def log_error ( _request , wrapper )
10- ActiveSupport ::Deprecation . silence do
11- ActionController ::Base . logger . fatal ( wrapper . exception )
9+ if ( Rails ::VERSION ::MAJOR == 7 && Rails ::VERSION ::MINOR >= 1 ) || Rails ::VERSION ::MAJOR > 7
10+ def log_error ( _request , wrapper )
11+ Rails . application . deprecators . silence do
12+ ActionController ::Base . logger . fatal ( wrapper . exception )
13+ end
14+ end
15+ else
16+ def log_error ( _request , wrapper )
17+ ActiveSupport ::Deprecation . silence do
18+ ActionController ::Base . logger . fatal ( wrapper . exception )
19+ end
1220 end
1321 end
1422 end
Original file line number Diff line number Diff line change @@ -84,5 +84,24 @@ class ArticlesControllerTest < ActionDispatch::IntegrationTest
8484 )
8585 end
8686 end
87+
88+ describe "#show" do
89+ it "raises and logs exception" do
90+ # we're testing ActionDispatch::DebugExceptions in fact
91+ messages = semantic_logger_events do
92+ old_show = Rails . application . env_config [ "action_dispatch.show_exceptions" ]
93+ begin
94+ Rails . application . env_config [ "action_dispatch.show_exceptions" ] = :all
95+ get article_url ( :show )
96+ rescue ActiveRecord ::RecordNotFound => e
97+ # expected
98+ ensure
99+ Rails . application . env_config [ "action_dispatch.show_exceptions" ] = old_show
100+ end
101+ end
102+ assert_equal 4 , messages . count , messages
103+ assert_kind_of ActiveRecord ::RecordNotFound , messages [ 3 ] . exception
104+ end
105+ end
87106 end
88107end
Original file line number Diff line number Diff line change 55 def create
66 render plain : params [ :article ] . inspect
77 end
8+
9+ def show
10+ raise ActiveRecord ::RecordNotFound
11+ end
812end
Original file line number Diff line number Diff line change 66
77module Dummy
88 class Application < Rails ::Application
9+ if config . respond_to? ( :load_defaults )
10+ config . load_defaults "#{ Rails ::VERSION ::MAJOR } .#{ Rails ::VERSION ::MINOR } "
11+ end
12+
913 # Configure sensitive parameters which will be filtered from the log file.
1014 config . filter_parameters += [ :password ]
1115 config . active_record . sqlite3 . represent_boolean_as_integer = true if config . active_record . sqlite3
Original file line number Diff line number Diff line change 1919 config . action_controller . perform_caching = false
2020
2121 # Raise exceptions instead of rendering exception templates
22- config . action_dispatch . show_exceptions = false
22+ config . action_dispatch . show_exceptions = Rails :: VERSION :: MAJOR >= 7 ? :none : false
2323
2424 # Disable request forgery protection in test environment
2525 config . action_controller . allow_forgery_protection = false
You can’t perform that action at this time.
0 commit comments