From 9e6dbc6d8330bccd13acd1c1b261417688475d7a Mon Sep 17 00:00:00 2001 From: pvincent Date: Sat, 22 Jun 2024 22:54:25 +0400 Subject: [PATCH] sql formatter sql ready --- lib/formatters/ansi_formatter.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/formatters/ansi_formatter.rb b/lib/formatters/ansi_formatter.rb index 535add2..1116501 100644 --- a/lib/formatters/ansi_formatter.rb +++ b/lib/formatters/ansi_formatter.rb @@ -119,7 +119,7 @@ class AnsiFormatter < SemanticLogger::Formatters::Color log.level = :debug log.message.lstrip! if log.name == 'ActiveRecord::Base' - unbold(log.message) + unbold!(log.message) if log.message.starts_with?('↳ ') log.message = AnsiCommon.ansi_trace(log.message, '⇄') @@ -130,8 +130,10 @@ class AnsiFormatter < SemanticLogger::Formatters::Color sql_type, sql_entry = sql_command.split("\e[0m") sql_color_entry = sql_entry.match(AnsiCommon::ANSI_REGEX).to_s sql_args = JSON.parse(sql_match.to_s).map(&:last) - sql_args.each_with_index do |value, index| - sql_entry.gsub!("$#{index + 1}", colorize(value.inspect, BOLD) + sql_color_entry) + sql_args.each_with_index do |val, index| + sql_arg = val.inspect + sql_arg = "'#{val.gsub("'", "''")}'" if val.is_a?(String) + sql_entry.gsub!("$#{index + 1}", colorize(sql_arg, BOLD) + sql_color_entry) end log.message = [sql_type, sql_entry].join(CLEAR) end @@ -178,7 +180,7 @@ class AnsiFormatter < SemanticLogger::Formatters::Color FAILOVER_WRAP end - def unbold(text) = text.gsub!(BOLD, '') + def unbold!(text) = text.gsub!(BOLD, '') def message colorize(log.message) if log.message