Browse Source

ansi_common

main
pvincent 7 months ago
parent
commit
05b65b5212
  1. 12
      lib/formatters/ansi_common.rb
  2. 12
      lib/formatters/ansi_formatter.rb

12
lib/formatters/ansi_common.rb

@ -0,0 +1,12 @@
require_relative 'ansi_colors'
# gather common definitions and functions
class AnsiCommon
def self.ansi_trace(trace)
match = trace.match(/(↳ )?(.*:\d+):in `(.*)'/)
return trace unless match
_, m2, m3 = match.captures
"#{m2} #{AnsiColors::BOLD}#{m3}#{AnsiColors::CLEAR}"
end
end

12
lib/formatters/ansi_formatter.rb

@ -1,6 +1,7 @@
require_relative 'ansi_wrapper'
require_relative 'ansi_colors'
require_relative 'ansi_dimensions'
require_relative 'ansi_common'
require 'io/console'
require 'amazing_print'
@ -81,6 +82,9 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
elsif log.name =~ /^(ActionView|ActiveRecord)::Base/
log.level = :debug
log.message.lstrip!
if log.name == 'ActiveRecord::Base' && log.message.starts_with?('↳ ')
log.message = AnsiCommon.ansi_trace(log.message)
end
end
log
@ -99,13 +103,7 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
def stackisize(items)
return '' if items.empty?
traces = items.map do |item|
trace = item.match(/(.*:\d+):in `(.*)'/)
next item unless trace
m1, m2 = trace.captures
"#{m1} #{AnsiColors::BOLD}#{m2}#{AnsiColors::CLEAR}"
end
traces = items.map { |item| AnsiCommon.ansi_trace(item) }
"\n#{traces.join("\n")}"
end

Loading…
Cancel
Save