lib/oboe/api/util.rb in oboe-1.3.7 vs lib/oboe/api/util.rb in oboe-1.3.8

- old
+ new

@@ -2,11 +2,11 @@ # All rights reserved. module Oboe module API module Util - BACKTRACE_CUTOFF = 100 + BACKTRACE_CUTOFF = 200 # Internal: Check whether the provided key is reserved or not. Reserved # keys are either keys that are handled by liboboe calls or the oboe gem. # # key - the key to check. @@ -22,16 +22,23 @@ # when you know how many layers deep in oboe the call is being # made. # # Returns a string with each frame of the backtrace separated by '\r\n'. def backtrace(ignore=1) - frames = Kernel.caller - frames_len = frames.size - if frames_len - ignore > BACKTRACE_CUTOFF - frames[ignore, BACKTRACE_CUTOFF + ignore].unshift("...") + trim_backtrace(Kernel.caller).join("\r\n"); + end + + def trim_backtrace(backtrace) + return backtrace unless backtrace.is_a?(Array) + + length = backtrace.size + if length > BACKTRACE_CUTOFF + # Trim backtraces by getting the first 180 and last 20 lines + trimmed = backtrace[0, 180] + ['...[snip]...'] + backtrace[length - 20, 20] else - frames.drop(ignore) - end.join("\r\n") + trimmed = backtrace + end + trimmed end end end end