3 changed files with 46 additions and 74 deletions
			
			
		- 
					40lib/semantic/abstract_formatter.rb
- 
					38lib/semantic/basic_formatter.rb
- 
					42lib/semantic/fancy_formatter.rb
| @ -1,5 +1,45 @@ | |||
| module Semantic | |||
|   # Abstract colorized formatter | |||
|   class AbstractFormatter < SemanticLogger::Formatters::Color | |||
|     include AnsiColors | |||
| 
 | |||
|     private | |||
| 
 | |||
|     def exception | |||
|       return unless log.exception | |||
| 
 | |||
|       if log.exception.is_a?(Semantic::TagWrapError) | |||
|         exc_wrapper = log.exception | |||
|         # puts "TAG_WRAP detected #{exc_wrapper.tag}" | |||
| 
 | |||
|         exc = exc_wrapper.error | |||
|         log.tags = Array.wrap(exc_wrapper.tag) | |||
|       else | |||
|         exc = log.exception | |||
|       end | |||
| 
 | |||
|       clazz = colorize("#{exc.class}\n", color_map[:fatal]) | |||
|       message = colorize(exc.message.chomp(''), color_map[:error]) | |||
| 
 | |||
|       # TODO: backtrace_cleaner might be optionally disable from Live::Constant | |||
|       backtrace = stackisize(Rails.backtrace_cleaner.clean(exc.backtrace)) | |||
| 
 | |||
|       "#{clazz}#{message}#{backtrace}" | |||
|     end | |||
| 
 | |||
|     def ansi_trace(trace, symbol) | |||
|       match = trace.match(/(↳ )?(.*:\d+)(:in `)?(.*'?)/) # only m2(=file) and m4(=optional function) are useful | |||
|       return trace unless match | |||
| 
 | |||
|       _, m2, _, m4 = match.captures | |||
|       "#{symbol} #{m2} #{BOLD}#{m4.chop}#{CLEAR}" | |||
|     end | |||
| 
 | |||
|     def stackisize(items) | |||
|       return '' if items.empty? | |||
| 
 | |||
|       traces = items.map { |item| ansi_trace(item, '➟') } | |||
|       "\n#{traces.join("\n")}" | |||
|     end | |||
|   end | |||
| end | |||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue