Browse Source

transform rails Started

pagy
pvincent 10 months ago
parent
commit
d44f90697e
  1. 25
      lib/formatters/basic_formatter.rb

25
lib/formatters/basic_formatter.rb

@ -11,6 +11,8 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
RENDERED_VIEW_DURATION = 100 RENDERED_VIEW_DURATION = 100
ANSI_RESET = "\e[0m".freeze
ANSI_BOLD = "\e[1m".freeze
ANSI_DEBUG = "\e[90m".freeze ANSI_DEBUG = "\e[90m".freeze
ANSI_INFO = SemanticLogger::AnsiColors::GREEN ANSI_INFO = SemanticLogger::AnsiColors::GREEN
ANSI_WARN = SemanticLogger::AnsiColors::YELLOW ANSI_WARN = SemanticLogger::AnsiColors::YELLOW
@ -28,6 +30,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
fatal: ANSI_REVERSED_FATAL fatal: ANSI_REVERSED_FATAL
) )
# exclude log eagerly!
EXCLUDE_LAMBDA = lambda { |log| EXCLUDE_LAMBDA = lambda { |log|
if log.name == 'ActionView::Base' if log.name == 'ActionView::Base'
!log.message.starts_with?(' Rendering') !log.message.starts_with?(' Rendering')
@ -110,17 +113,29 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
draw_rails('┆') draw_rails('┆')
end end
# transform log before display
def transform_log(log) def transform_log(log)
if log.name == 'ActionView::Base' if log.name == 'ActionView::Base'
log = transform_action_view_base(log) log = transform_action_view_base(log)
elsif log.name == 'Rails' && log.message elsif log.name == 'Rails' && log.message
message = log.message.rstrip
message += "\n" if message.starts_with?('Completed 2') || message.starts_with?('Completed 3')
log.message = message
log.message = transform_rails_message(log.message)
end end
log log
end end
def transform_rails_message(message)
message.rstrip!
case message
when /^Completed [23]/
"#{message}\n"
when /^Started/
md = message.match(/(^Started \w* )"(.*?)"/)
"#{md.match(1)}#{ANSI_BOLD}#{md.match(2)}#{ANSI_RESET}"
else
message
end
end
def transform_action_view_base(log) def transform_action_view_base(log)
log.level, message = transform_log_debug_lstrip(log) log.level, message = transform_log_debug_lstrip(log)
message = transform_rendered_message_with_filename(message) message = transform_rendered_message_with_filename(message)
@ -170,9 +185,9 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
end end
def backtrace(stack) def backtrace(stack)
return unless stack.count.positive?
return "\n" unless stack.count.positive?
"\n#{before_message} #{ANSI_ERROR}#{stack.join("\n#{before_message} #{ANSI_ERROR}")}#{color_map.clear}"
"\n#{before_message} #{ANSI_ERROR}#{stack.join("\n#{before_message} #{ANSI_ERROR}")}#{color_map.clear}\n"
end end
def color_content def color_content

Loading…
Cancel
Save