From 67296b05920fff2a444455d4b919e45b329862e1 Mon Sep 17 00:00:00 2001 From: pvincent Date: Wed, 24 Jan 2024 11:07:35 +0400 Subject: [PATCH] refactor2 --- lib/formatters/basic_formatter.rb | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/formatters/basic_formatter.rb b/lib/formatters/basic_formatter.rb index 4e66e00..144ee8b 100644 --- a/lib/formatters/basic_formatter.rb +++ b/lib/formatters/basic_formatter.rb @@ -145,19 +145,22 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri def transform_rails_message(message) case message - when /^Completed/ - transform_rails_completed(message) - when /^Started/ - two_captures_last_as_bold(message, /(^Started \w* )"(.*?)"/) - when /^Processing/ - "#{PREFIX_RAILS_INTERNAL}#{two_captures_last_as_bold(message, /(^Processing by \w*#\w* as )(.*)/)}" - when / Parameters/ - parameters = message.lstrip.match(/Parameters: ({.*}$)/).match(1) - parameters = JSON.parse(parameters.gsub('=>', ':'), symbolize_names: true) - "#{PREFIX_RAILS_INTERNAL}Parameters: #{parameters.ai(ruby19_syntax: true, plain: true, multiline: false)}" - else - message - end + when /^Completed/ then transform_rails_completed(message) + when /^Started/ then two_captures_last_as_bold(message, /(^Started \w* )"(.*?)"/) + when / Parameters/ then transform_rails_parameters(message) + when /^Processing/ then transform_rails_processing(message) + else message end + end + + def transform_rails_processing(message) + message = two_captures_last_as_bold(message, /(^Processing by \w*#\w* as )(.*)/) + "#{PREFIX_RAILS_INTERNAL}#{message}" + end + + def transform_rails_parameters(message) + parameters = message.lstrip.match(/Parameters: ({.*}$)/).match(1) + parameters = JSON.parse(parameters.gsub('=>', ':'), symbolize_names: true) + "#{PREFIX_RAILS_INTERNAL}Parameters: #{parameters.ai(ruby19_syntax: true, plain: true, multiline: false)}" end def transform_rails_completed(message)