Browse Source

refactor4

main
pvincent 4 months ago
parent
commit
6bf1bbead3
  1. 17
      lib/formatters/basic_formatter.rb

17
lib/formatters/basic_formatter.rb

@ -91,15 +91,13 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
ansi_wrap(log.name.truncate(NAME_MAX_SIZE).center(NAME_MAX_SIZE), ANSI_DEBUG)
end
def exception # rubocop:disable Metrics/AbcSize
def exception
return unless log.exception
root_path = Rails.root.to_s
stack = log.exception.backtrace.select { |line| line.starts_with?(root_path) }
stack = stack.map { |line| line.delete_prefix("#{root_path}/") }
backtrace = backtrace(log.exception)
"#{ansi_wrap(log.exception.class,
ANSI_REVERSED_WARNING)} #{ansi_wrap(log.exception.message, ANSI_REVERSED_ERROR)}#{backtrace(stack)}"
ANSI_REVERSED_WARNING)} #{ansi_wrap(log.exception.message, ANSI_REVERSED_ERROR)}#{backtrace}"
end
def call(log, logger)
@ -230,9 +228,14 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
[name, wrapped ? continuation : level, tags, named_tags, duration].compact.join(' ') + CONTENT_PREFIX
end
def backtrace(stack)
def backtrace(exception)
root_path = Rails.root.to_s
stack = exception.backtrace.select { |line| line.starts_with?(root_path) }
stack = stack.map { |line| line.delete_prefix("#{root_path}/") }
return "\n" unless stack.count.positive?
"\n#{before_message}#{ANSI_ERROR}#{PREFIX_BUG_INTERNAL}#{stack.join("\n#{before_message}#{ANSI_ERROR}#{PREFIX_BUG_INTERNAL}")}#{color_map.clear}\n"
stack_message = PREFIX_BUG_INTERNAL
stack_message += stack.join("\n#{before_message}#{ANSI_ERROR}#{PREFIX_BUG_INTERNAL}")
"\n#{before_message}#{ansi_wrap(stack_message, ANSI_ERROR)}\n"
end
end
Loading…
Cancel
Save