File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1+ module LogStasher
2+ module ActionDispatch
3+ class DebugExceptions < ::ActionDispatch ::DebugExceptions
4+ private
5+ def log_error ( env , wrapper )
6+ logger = logger ( env )
7+ return unless logger
8+
9+ ::ActiveSupport ::Deprecation . silence do
10+ logger << LogStasher . build_logstash_event ( build_exception_hash ( wrapper ) , [ "exception" ] ) . to_json + "\n "
11+ end
12+ end
13+
14+ def build_exception_hash ( wrapper )
15+ exception = wrapper . exception
16+ trace = wrapper . application_trace
17+ trace = wrapper . framework_trace if trace . empty?
18+
19+ { error :
20+ ( { exception : exception . class , message : exception . message , trace : trace } .
21+ merge! ( exception . respond_to? ( :annotated_source_code ) && { annotated_source_code : exception . annoted_source_code } || { } ) )
22+ }
23+ end
24+ end
25+ end
26+ end
Original file line number Diff line number Diff line change 11require 'rails/railtie'
22require 'action_view/log_subscriber'
33require 'action_controller/log_subscriber'
4+ require 'logstasher/rails_ext/rack/debug_exceptions'
45require 'socket'
56
67module LogStasher
@@ -33,8 +34,10 @@ class Railtie < Rails::Railtie
3334 LogStasher . setup_before ( app . config . logstasher ) if app . config . logstasher . enabled
3435 end
3536
36- initializer :logstasher do
37- config . after_initialize do
37+ initializer :logstasher do |app |
38+ app . config . middleware . use ::LogStasher ::ActionDispatch ::DebugExceptions
39+ app . config . middleware . delete ::ActionDispatch ::DebugExceptions if Rails . env . production?
40+ app . config . after_initialize do
3841 LogStasher . setup ( config . logstasher ) if config . logstasher . enabled
3942 end
4043 end
You can’t perform that action at this time.
0 commit comments