Module: NdrError::BacktraceCompression
- Included in:
- Log
- Defined in:
- lib/ndr_error/backtrace_compression.rb
Overview
Mixin to help compressing/expanding stored backtraces.
Instance Method Summary collapse
-
#application_trace ⇒ Object
Attempts to return just the “application” trace, so we can highlight “our” code vs.
-
#backtrace ⇒ Object
Returns the backtrace as an array.
-
#backtrace=(trace) ⇒ Object
Stores as much of the backtrace as is possible in a string.
Instance Method Details
#application_trace ⇒ Object
Attempts to return just the “application” trace, so we can highlight “our” code vs. 3rd-party libraries.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ndr_error/backtrace_compression.rb', line 6 def application_trace app_trace = backtrace.select do |line| app = line =~ %r{/(#{Rails.root.basename}|current|releases)/} ndr = line =~ %r{/gems/ndr_} app || ndr end app_trace = backtrace.reject { |line| line =~ %r{/gems/} } if app_trace.blank? app_trace end |
#backtrace ⇒ Object
Returns the backtrace as an array.
19 20 21 |
# File 'lib/ndr_error/backtrace_compression.rb', line 19 def backtrace inflate_backtrace(lines) end |
#backtrace=(trace) ⇒ Object
Stores as much of the backtrace as is possible in a string. Splits out any nested lines, e.g. TemplateError backtrace.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ndr_error/backtrace_compression.rb', line 25 def backtrace=(trace) array = trace ? trace.dup : [] array = array.map { |line| line.split("\n") }.flatten dump = deflate_backtrace(array) while dump.length >= 4000 array.pop dump = deflate_backtrace(array) end self.lines = dump end |