Browse Source

transform_rails_message refactored

pagy
pvincent 11 months ago
parent
commit
b27c0c88fb
  1. 1
      app/controllers/scores_controller.rb
  2. 13
      lib/formatters/basic_formatter.rb

1
app/controllers/scores_controller.rb

@ -12,6 +12,7 @@ class ScoresController < ApplicationController
# logger.debug BigDecimal('0.0003')
# logger.debug 'scores are', @scores
# logger.debug @scores
# sleep 1
end
# GET /scores/1

13
lib/formatters/basic_formatter.rb

@ -118,24 +118,29 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
if log.name == 'ActionView::Base'
log = transform_action_view_base(log)
elsif log.name == 'Rails' && log.message
log.message = transform_rails_message(log.message)
log.message = transform_rails_message(log.message.rstrip)
end
log
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}"
two_captures_last_as_bold(message, /(^Started \w* )"(.*?)"/)
when /^Processing/
two_captures_last_as_bold(message, /(^Processing by \w*#\w* as )(.*)/)
else
message
end
end
def two_captures_last_as_bold(message, regex)
m1, m2 = message.match(regex).captures
"#{m1}#{ANSI_BOLD}#{m2}#{ANSI_RESET}"
end
def transform_action_view_base(log)
log.level, message = transform_log_debug_lstrip(log)
message = transform_rendered_message_with_filename(message)

Loading…
Cancel
Save