Skip to content
Browse files

Merge fix: consoldate use of last exception

  • Loading branch information...
2 parents 30f3452 + c9bafbe commit 0e57be07e7e3713c249b2d01d2dc67603bf71307 @marcbowes marcbowes committed
Showing with 3 additions and 10 deletions.
  1. +3 −10 lib/safely/backtrace.rb
View
13 lib/safely/backtrace.rb
@@ -15,24 +15,17 @@ def safe_shutdown!
end
def log_exceptions
- STDERR.puts("In #log_exceptions. @enabled=#{@enabled}, trace_directory=#{trace_directory}")
return unless @enabled && self.trace_directory && File.directory?( self.trace_directory )
+ return if (last_exception = $!).nil?
require 'logger'
trace_file = File.join( self.trace_directory, "backtrace-#{Time.now.strftime('%Y%m%d%H%M%S')}-#{Process.pid}.log" )
trace_log = Logger.new( trace_file )
- # Find the last exception
- e = nil
- ObjectSpace.each_object {|o|
- if ::Exception === o
- e = o
- end
- }
-
+ # Log the last exception
trace_log.info "*** Below you'll find the most recent exception thrown, this will likely (but not certainly) be the exception that made your application exit abnormally ***"
- trace_log.error e
+ trace_log.error last_exception
trace_log.info "*** Below you'll find all the exception objects in memory, some of them may have been thrown in your application, others may just be in memory because they are standard exceptions ***"
ObjectSpace.each_object {|o|

0 comments on commit 0e57be0

Please sign in to comment.
Something went wrong with that request. Please try again.